Help with VB

ctark

Senior member
Sep 6, 2004
726
1
0
I'm having 2 problems with this program. Yes its a homework assignment and I have figured most of it out myself, I'm just stuck on a few things.

Problem 1: FIXED When I clear the text boxes and try to recalculate it somehow remembers the data. So lets say i put in quantity two of cappuccino and hit calculate. It comes out to a total of $4 and. I hit clear and do it again and now my Total comes out to $8. FIXED

Problem 2: For some reason my Latte, Iced Latte, and Iced Cappuccino radio buttons dont work. When I click on them and calculate it comes out with a total of $0. I cant for the life of me figure out why it would do this, the code looks fine to me.

Here is a pic of the design view so you can get an idea.




Here is my source code:

Public Class billingForm
' Declare project wide variables.
Friend priceDecimal, averageDecimal As Decimal
Friend customerCounterInteger As Integer


'Declare module-level variables.
Private subTotalDecimal, totalDecimal As Decimal

' Declare constants.
Const TAX_RATE_Decimal As Decimal = 0.08D
Const CAPPUCCINO_P As Decimal = 2D
Const ESPRESSO_P As Decimal = 2.25D
Const LATTE_P As Decimal = 1.75D
Const ICED_P As Decimal = 2.5D
Const ICED_C As Decimal = 3D


Private Sub calculateButton_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles calculateButton.Click
' Calculate and display the current amounts and add to totals
Dim price_Decimal, taxDecimal, itemAmountDecimal As Decimal
Dim quantityInteger As Integer

With Me
' Find the price
If .cappuccinoRadioButton.Checked Then
priceDecimal = CAPPUCCINO_P
ElseIf .espressoRadioButton.Checked Then
priceDecimal = ESPRESSO_P
ElseIf .latteRadioButton.Checked Then
price_Decimal = LATTE_P
ElseIf .icedlatteradiobutton.Checked Then
price_Decimal = ICED_P
ElseIf .icedcapuccinoradiobutton.Checked Then
price_Decimal = ICED_C
Else
MessageBox.Show("Please make a drink selection", "Selection Required", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

'Calculate the extended price and add to order total
Try
quantityInteger = Integer.Parse(.quantityTextBox.Text)
itemAmountDecimal = priceDecimal * quantityInteger
subTotalDecimal += itemAmountDecimal
If .taxCheckBox.Checked Then
taxDecimal = FindTax(subTotalDecimal)
Else
taxDecimal = 0
End If
totalDecimal = subTotalDecimal + taxDecimal
.itemAmountTextBox.Text = itemAmountDecimal.ToString("C")
.subTotalTextBox.Text = subTotalDecimal.ToString("N")
.taxTextBox.Text = taxDecimal.ToString("N")
.totalTextBox.Text = totalDecimal.ToString("C")
'Allow Clear after an order is begun
.clearButton.Enabled = True
Catch quantityException As FormatException
MessageBox.Show("Enter the quantity", "Data entry error", MessageBoxButtons.OK, MessageBoxIcon.Information)
With .quantityTextBox
.Focus()
.SelectAll()

End With
End Try
End With
End Sub
Private Function FindTax(ByVal amountDecimal As Decimal)
'Calculate the sales tax
Return amountDecimal * TAX_RATE_Decimal
End Function
Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click
'clear the appropriate controls
With Me
.cappuccinoRadioButton.Checked = True
.espressoRadioButton.Checked = True
.icedlatteradiobutton.Checked = True
.icedcapuccinoradiobutton.Checked = True
.latteRadioButton.Checked = True
.quantityTextBox.Clear()
.itemAmountTextBox.Clear()
.taxTextBox.Clear()
.subTotalTextBox.Clear()
.totalTextBox.Clear()
End With

End Sub

Private Sub taxCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles taxCheckBox.CheckedChanged

End Sub

Private Sub taxTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles taxTextBox.TextChanged

End Sub

Private Sub cappuccinoRadioButton_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cappuccinoRadioButton.CheckedChanged

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
End Class
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,836
4,815
75
' Find the price
If .cappuccinoRadioButton.Checked Then
priceDecimal = CAPPUCCINO_P
ElseIf .espressoRadioButton.Checked Then
priceDecimal = ESPRESSO_P
ElseIf .latteRadioButton.Checked Then
price_Decimal = LATTE_P
ElseIf .icedlatteradiobutton.Checked Then
price_Decimal = ICED_P
ElseIf .icedcapuccinoradiobutton.Checked Then
price_Decimal = ICED_C
Else
musicnote.gif
Some of these things
Are not like the others.
musicnote.gif


Also, use [code] tags.
 

ctark

Senior member
Sep 6, 2004
726
1
0
musicnote.gif
Some of these things
Are not like the others.
musicnote.gif


Also, use [code] tags.

Yes I finally found that out. You see our professor doesn't like to each us anything, she just says here's your assignment and here's the source code for your assignment. She gives us almost the exact source code needed to complete the assignment, which I think is BS. Whats funny is her source code is riddled with errors in it and they aren't on purpose.