Hi,
18. Validating the data entered in the Amount TextBox control.
This event occurs when the input focus leaves the control. This event procedure is to check for whether data entered in amount text box control is valid.
Private Sub mAmount_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles mAmount.LostFocus
If Not IsNumeric(mAmount.Text) And mAmount.Text <> " " Then
MsgBox("Not a Numeric Input! Try again.")
mAmount.Focus()
Exit Sub
ElseIf (mAmount.Text < 0) Then
MessageBox.Show("Enter positive Amount")
mAmount.Focus()
Exit Sub
End If
End Sub
The TextChanged event occurs when the content in the TextBox control is changed. Select mAmount in LHS combobox and TextChanged in the RHS combobox to program this event. We use IsNumeric() function to check the value entered in the amount text box control is numeric data. We also check whether the value entered in this text box is empty. If any of these conditions are true, then we will display a message box and set the focus to the Amount text box control.
Private Sub mAmount_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles mAmount.TextChanged
If Not IsNumeric(mAmount.Text) And mAmount.Text <> " " Then
MsgBox("Not a Numeric Input! Try again.")
mAmount.Focus()
Exit Sub
End If
End Sub
|