1 Replies - 588 Views - Last Post: 09 May 2013 - 02:15 AM Rate Topic: -----

#1 aloosha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-May 13

my price calculator always reads zero

Posted 09 May 2013 - 01:37 AM

I'm really not very good at any programming language, but my teacher is horrible and I've been trying to teach myself visual basic.
I'm writing a code to calculate the wholesale price of pumpkins and retail price of pumpkins. For wholesale the price is $10 for each from 1 to 4 pumpkins and 9$ each for five or more pumpkins. For retail the price is 15$ each for 1 to 3 pumpkins, 14$ each for 4 to 8 pumpkins and 13$ each for 9 or more pumpkins. I think my code looks correct and I'm not getting any errors but when I run it it always displays the price as zero. Where am I going wrong?

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcWholesale.Click
        Dim numberWholesale As Integer
        Const WholePrice As Decimal

        Select Case numberWholesale
            Case 1 To 4
                WholePrice = 10
            Case Is > 4
                WholePrice = 9
        End Select

        WholePrice = numberWholesale * WholePrice

        Integer.TryParse(numberWholesaleTextBox.Text, numberWholesale)
        Integer.TryParse(wholePriceLabel.Text, WholePrice)


        wholePriceLabel.Text = Convert.ToString(WholePrice)



    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calcRetail.Click
        Const RetailPrice As Integer
        Dim numberRetail As Integer

        Select Case numberRetail
            Case 1 To 3
                RetailPrice = 15D
            Case 4 To 8
                RetailPrice = 14D
            Case Is > 8
                RetailPrice = 13D
        End Select

        RetailPrice = numberRetail * RetailPrice

        Integer.TryParse(numberRetailTextBox.Text, numberRetail)
        Integer.TryParse(retailPriceLabel.Text, RetailPrice)

        retailPriceLabel.Text = Convert.ToString(RetailPrice)

    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: my price calculator always reads zero

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3621
  • View blog
  • Posts: 12,510
  • Joined: 12-December 12

Re: my price calculator always reads zero

Posted 09 May 2013 - 02:15 AM

Const WholePrice As Decimal

You cannot define this as a constant if you intend to change its value. The same applies to RetailPrice.

These prices will have default values of 0.0, which won't change. (I'm surprised you can run the program tbh.)

This post has been edited by andrewsw: 09 May 2013 - 03:12 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1