W
Wolff1029
Guest
Hi,
Im a bit stumped as to why I have to click twice to produce the correct calculation in my program. It is a simple application that is supposed to calculate the cost based on the number of units ordered. The price per unit changes based on if it is a retailer or wholesaler and depending on the number of units ordered. For example when I first click calculate after entering 1 into the input box it should run the calculation 1*10 and output a value of $10.00 (in this case wholesaler is selected in a radio button), instead it displays $0.00. If I hit calculate again it changes to the correct value $10.00. Then if I change the input value to 2 and hit calculate it displays the previous total $10.00, and if I hit calculate again it displays the correct amount $20.00. I want to code it so that it only requires one click of the calculate button to correctly display the total.
If anyone has any ideas about fixing this please let me know.
Thanks,
Austin
Here is my Code:
Public Class MainForm
Private Units As Double = 0.0
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtUnits_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUnits.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim Total As Integer
Dim Price As Integer
If Wholesale.Checked = True Then
Select Case Units
Case 1 To 4
Price = 10
Case Is > 4
Price = 9
End Select
ElseIf Retail.Checked = True Then
Select Case Units
Case 1 To 3
Price = 15
Case 4 To 8
Price = 14
Case Is > 8
Price = 12
End Select
End If
Total = CInt(Units * Price)
Units = Convert.ToInt32(txtUnits.Text)
lblTotal.Text = Total.ToString("C2")
End Sub
Private Sub ClearPayment(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUnits.TextChanged, Retail.CheckedChanged, Wholesale.CheckedChanged
lblTotal.Text = String.Empty
End Sub
End Class
Continue reading...
Im a bit stumped as to why I have to click twice to produce the correct calculation in my program. It is a simple application that is supposed to calculate the cost based on the number of units ordered. The price per unit changes based on if it is a retailer or wholesaler and depending on the number of units ordered. For example when I first click calculate after entering 1 into the input box it should run the calculation 1*10 and output a value of $10.00 (in this case wholesaler is selected in a radio button), instead it displays $0.00. If I hit calculate again it changes to the correct value $10.00. Then if I change the input value to 2 and hit calculate it displays the previous total $10.00, and if I hit calculate again it displays the correct amount $20.00. I want to code it so that it only requires one click of the calculate button to correctly display the total.
If anyone has any ideas about fixing this please let me know.
Thanks,
Austin
Here is my Code:
Public Class MainForm
Private Units As Double = 0.0
Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub txtUnits_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUnits.KeyPress
If (e.KeyChar < "0" OrElse e.KeyChar > "9") _
AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim Total As Integer
Dim Price As Integer
If Wholesale.Checked = True Then
Select Case Units
Case 1 To 4
Price = 10
Case Is > 4
Price = 9
End Select
ElseIf Retail.Checked = True Then
Select Case Units
Case 1 To 3
Price = 15
Case 4 To 8
Price = 14
Case Is > 8
Price = 12
End Select
End If
Total = CInt(Units * Price)
Units = Convert.ToInt32(txtUnits.Text)
lblTotal.Text = Total.ToString("C2")
End Sub
Private Sub ClearPayment(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUnits.TextChanged, Retail.CheckedChanged, Wholesale.CheckedChanged
lblTotal.Text = String.Empty
End Sub
End Class
Continue reading...