this works with 4 textboxes + 4 checkboxes
(named textbox1, textbox2, checkbox1, checkbox2, etc)
vb Code:
Private Sub TextBoxes_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged doTotal() End Sub Private Sub CheckBoxes_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles CheckBox1.CheckedChanged, CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged doTotal() End Sub Private Sub doTotal() Dim total As Decimal = 0 For x As Integer = 1 To 4 If DirectCast(Me.Controls("checkbox" & x), CheckBox).Checked Then total += CDec(Val(DirectCast(Me.Controls("textbox" & x), TextBox).Text)) Else total -= CDec(Val(DirectCast(Me.Controls("textbox" & x), TextBox).Text)) End If Next Label1.Text = CStr(total) End Sub
you'd have to modify the handles statements in TextBoxes_TextChanged + CheckBoxes_CheckedChanged to include 14 textboxes + checkboxes




Reply With Quote