# my price calculator always reads zero

Page 1 of 1

## 1 Replies - 1511 Views - Last Post: 09 May 2013 - 02:15 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=320635&amp;s=b89718f269aa9e30afb6c4363b7f4b0e&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 aloosha

Reputation: 0
• 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

• the case is sol-ved

Reputation: 6375
• Posts: 25,756
• 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