I'm a complete newbie when it comes to programming in VB.net (started last week). I have an assignment in class that requires me to do a running total using 3 checkboxes.
I've figured out a little bit of it. My main problem right now is that when I uncheck boxes, the calculation gets weird. So far here is my code:
Public Class frm1
Dim HandbagAcc As Double = 0
Private Sub chkBoxExtra_CheckedChanged(sender As Object, e As EventArgs) Handles chkBoxExtra.CheckedChanged
'$9.99
If chkBoxExtra.Checked = True Then
HandbagAcc = HandbagAcc + 9.99
txtBoxAcc.Text = FormatCurrency(HandbagAcc)
End If
If chkBoxExtra.Checked = False Then
HandbagAcc = HandbagAcc - 9.99
txtBoxAcc.Text = FormatCurrency(HandbagAcc)
End If
End Sub
Private Sub chkBoxMatching_CheckedChanged(sender As Object, e As EventArgs) Handles chkBoxMatching.CheckedChanged
'$7.99
If chkBoxExtra.Checked = True Then
HandbagAcc = HandbagAcc + 7.99
txtBoxAcc.Text = FormatCurrency(HandbagAcc)
End If
If chkBoxExtra.Checked = False Then
HandbagAcc = HandbagAcc - 7.99
txtBoxAcc.Text = FormatCurrency(HandbagAcc)
End If
End Sub
Private Sub chkBoxFour_CheckedChanged(sender As Object, e As EventArgs) Handles chkBoxFour.CheckedChanged
'$3.95
If chkBoxExtra.Checked = True Then
HandbagAcc = HandbagAcc + 3.95
txtBoxAcc.Text = FormatCurrency(HandbagAcc)
End If
If chkBoxExtra.Checked = False Then
HandbagAcc = (HandbagAcc - 3.95)
txtBoxAcc.Text = FormatCurrency(HandbagAcc)
End If
End Sub
End Class
When I check the three checkboxes the first time, the values add up nicely--but, when I uncheck a box or two, my numbers go wonky and the calculation doesn't add up. What am I doing wrong?
Any help would be much appreciated. Thank you!
Aucun commentaire:
Enregistrer un commentaire