In: Computer Science
using visual basic
how would i go about coding:
if checkbox 1 is checked add 10 to subtotal
if checkbox 2 is checked add 50 to subtotal
if checkbox 3 is checked add 100 to subtotal
subtotal label is 'lblSubtotal'
all 3 boxes are independent.
example if checkboxes 1 and 3 are checked 110 would be added to
subtotal.
Program
Public Class Form1
'Declare a variable Subtotal
Dim Subtotal As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub chk10_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chk10.CheckedChanged
'Checking Checkbox1 is checked or not
If chk10.Checked = True Then
Subtotal = 10 'add 10 to Subtotal
lblSubtotal.Text = Convert.ToString(Subtotal)
End If
End Sub
Private Sub chk50_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chk50.CheckedChanged
'Checking Checkbox2 is checked or not
If chk50.Checked = True Then
Subtotal = Subtotal + 50 'add 50 to Subtotal
lblSubtotal.Text = Convert.ToString(Subtotal)
End If
End Sub
Private Sub chk100_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chk100.CheckedChanged
'Checking Checkbox3 is checked or not
If chk100.Checked = True Then
Subtotal = Subtotal + 100 'add 100 to Subtotal
lblSubtotal.Text = Convert.ToString(Subtotal)
End If
End Sub
End Class
Output Screenshot