audio_uphoria
Active member
- Joined
- Jan 28, 2009
- Messages
- 31
- Programming Experience
- Beginner
Hello, for some reason I can't get this to work. I am making an app that will let the user put in the amount of pounds of coffee they want to order and they can order either regular or decaf. Each one has its own dim variable and is calculated after the click event of the calc button. I want to be able to add decimals if the user would want lets say 1.5lbs of regular and 2.3 lbs of decaf. Here is my non working code.... as you can see I tried to convert the text into decimal using try parse but when I run the program and enter whole numbers it works fine, when I enter 1.8 for reg and 5.3 for decaf for example all my output is zero. Please, enlighten me.
Sorry for it being long just wanted to make sure I didn't omit any important info
VB.NET:
' Declare Variables
Const tax As Decimal = 0.065D
Const regularPrice As Decimal = 6.99D
Const decafPrice As Decimal = 5.99D
Dim regular As Decimal
Dim decaf As Decimal
Dim isConverted As Boolean
Dim totalPound As Integer
Dim totalPrice As Decimal
Dim priceBefore As Decimal
Dim CurrentTax As Decimal
' Convert input
isConverted = Decimal.TryParse(txtRegular.Text, _
NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, regular)
isConverted = Decimal.TryParse(txtDecaf.Text, _
NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, decaf)
' Calculate (in order) Pounds, Price before, Tax, and Total Price
totalPound = CInt(regular + decaf)
' If order exceeds 1000lbs in any combination of coffee ordered then message states more than 1000lbs unavailable
If totalPound > 1000 Then
MessageBox.Show("I'm sorry, our warehouse does not currently stock no more than 500lbs of either type of coffee.")
lblTotalPounds.Text = ""
lblPriceBefore.Text = ""
lblTax.Text = ""
lblTotal.Text = ""
txtRegular.Focus()
End If
priceBefore = CDec((regular * regularPrice) + (decaf * decafPrice))
CurrentTax = priceBefore * tax
totalPrice = CurrentTax + priceBefore
' Dispplay Calculated Results
lblTotalPounds.Text = Convert.ToString(totalPound)
lblPriceBefore.Text = priceBefore.ToString("C")
lblTax.Text = CurrentTax.ToString("C")
lblTotal.Text = totalPrice.ToString("C")
End Sub