'Form level variables
Private WithEvents ctl As Control
Private refCtl As New TextBox
Private GIDollars As Double = 0
Private Deductions As Double = 0
Private Parents As Double = 0
Private Bonus As Double = 0
Private Personal As Double = 0
Private EPF As Double = 0
'Sets the initial reference for ctl to the forms active control
Private Sub frmComboExample_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
Me.ctl = Me.ActiveControl
End Sub
'Single event handler for all controls on the form, can be extended...
Private Sub ctl_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ctl.Leave
'If the length of the text in the text box is 0, an error occurs...
'Probably better if a try block were here...
If ctl.GetType.Equals(refCtl.GetType) And ctl.Text.Length < 1 Then Exit Sub
Select Case ctl.Name
Case Me.gross_TextBox.Name
GIDollars = Convert.ToDouble(Me.gross_TextBox.Text)
ctl.Text = Format(GIDollars, "#,###.00")
Case Me.bonus_TextBox.Name
Bonus = Convert.ToDouble(Me.bonus_TextBox.Text)
ctl.Text = Format(Bonus, "#,###.00")
End Select
Me.ctl = Me.ActiveControl
Me.taxable_TextBox.Text = Format(GIDollars + Bonus - Deductions - Personal - Parents - EPF, "#,###.00")
End Sub