When I select a checkbox, the value gets added in the textbox and gets incremented when I check another. Problem is, when I uncheck them, it should subtract the values too. Total_sum in my textbox. Please help me.
Dim sum As Integer
Public Sub ChangeValue(add As Boolean, value As Decimal)
sum += If(add, value, -value)
Total_sum.Text = sum.ToString
End Sub
Private Sub chk_1_CheckedChanged(sender As Object, e As EventArgs) Handles chk_1.CheckedChanged
If chk_1.Checked = True Then
ChangeValue(DirectCast(sender, CheckBox).Checked = True, 25I)
End If
End Sub
Private Sub chk_2_CheckedChanged(sender As Object, e As EventArgs) Handles chk_2.CheckedChanged
If chk_2.Checked = True Then
ChangeValue(DirectCast(sender, CheckBox).Checked, 25I)
End If
End Sub
Private Sub chk_3_1_CheckedChanged(sender As Object, e As EventArgs) Handles chk_3_1.CheckedChanged
If chk_3_1.Checked = True Then
chk_3_2.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 15I)
End If
End Sub
Private Sub chk_3_2_CheckedChanged(sender As Object, e As EventArgs) Handles chk_3_2.CheckedChanged
If chk_3_2.Checked = True Then
chk_3_1.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 30I)
End If
End Sub
Private Sub chk_4_CheckedChanged(sender As Object, e As EventArgs) Handles chk_4.CheckedChanged
If chk_4.Checked = True Then
ChangeValue(DirectCast(sender, CheckBox).Checked, 20D)
End If
End Sub
Private Sub chk_5_1_CheckedChanged(sender As Object, e As EventArgs) Handles chk_5_1.CheckedChanged
If chk_5_1.Checked = True Then
chk_5_2.Checked = False
chk_5_3.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 0D)
End If
End Sub
Private Sub chk_5_2_CheckedChanged(sender As Object, e As EventArgs) Handles chk_5_2.CheckedChanged
If chk_5_2.Checked = True Then
chk_5_1.Checked = False
chk_5_3.Checked = False
ChangeValue(DirectCast(sender, CheckBox).Checked, 15D)
End If
End Sub
Aucun commentaire:
Enregistrer un commentaire