How to find the sum of multiple check boxes

  • Thread starter Thread starter Jonezzy
  • Start date Start date
J

Jonezzy

Guest
My code seems to be wrong, when i run the app the output just gives the number of the greatest checkbox...i need the app to give the total of all check boxes that i have selected.



Public Class Form1
Private Sub btnCheckout_Click(sender As Object, e As EventArgs) Handles btnCheckout.Click

'Declaring groups
Dim dblHoodies, dblShirts, dblTanks, dblFlags, dblTotal As Double

'Hoodies price
If Hoodie1.Checked Then
dblHoodies = 45.0
ElseIf Hoodie2.Checked Then
dblHoodies = 40.0
ElseIf Hoodie3.Checked Then
dblHoodies = 58.0

'Flags price
ElseIf Flag1.Checked Then
dblFlags = 30
ElseIf Flag2.Checked Then
dblFlags = 30
ElseIf Flag3.Checked Then
dblFlags = 35

'Tanks price
ElseIf Tank1.Checked Then
dblTanks = 10
ElseIf Tank2.Checked Then
dblTanks = 17
ElseIf Tank3.Checked Then
dblTanks = 10

'Shirts price
ElseIf Shirt1.Checked Then
dblShirts = 10
ElseIf Shirt2.Checked Then
dblShirts = 10
ElseIf Shirt3.Checked Then
dblShirts = 12
End If
'Checkout function, once checkout button is clicked

PictureBox1.Visible = True

dblTotal = dblShirts + dblTanks + dblFlags + dblHoodies

Const Format As String = "C2"
lblOutput.Text = "Your total is: " & dblTotal.ToString(Format) & ControlChars.NewLine



End Sub
'When form runs, the loading button will be hidden
Private Sub loadingIcon_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PictureBox1.Visible = False
End Sub

Private Sub PBReset_Click(sender As Object, e As EventArgs) Handles PBReset.Click

'When reset button is hit all varibles of form will reset back to when the form was started

'Hoodie will uncheck
Hoodie1.Checked = False
Hoodie2.Checked = False
Hoodie3.Checked = False
'Flags will uncheck
Flag1.Checked = False
Flag2.Checked = False
Flag3.Checked = False

'Shirts will uncheck
Shirt1.Checked = False
Shirt2.Checked = False
Shirt3.Checked = False

'Tanks will uncheck
Tank1.Checked = False
Tank2.Checked = False
Tank3.Checked = False

'Total Label and Loading GIF reset
lblOutput.Text = "Your total is"
PBReset.Visible = True
PictureBox1.Visible = False

End Sub
End Class

Continue reading...
 
Back
Top