The "Validate event" : The TextBox has a CausesValidation property that can be True or False. If it is True, the Validate event will be invoked as soon as I try to leave the box. If I decide not to validate, in response to a question, for example, I can set the CausesValidation to False. Here is an example of a TextBox with Validate individual:
Code:
Private Sub txtHeures_Validate (Cancel As Boolean)
If txtHeures <0 Or txtHeures> 100 Then
MsgBox ("Must be a number between 0 and 100")
Cancel = True
End If
End Sub
Here is the Validate TextBox if part of a control array - the index should be included:
Code:
Private Sub txtHeures_Validate (Index As Integer, Cancel As Boolean)
If txtHeures (Index) <0 txtHeures Gold (Index)> 100 Then
MsgBox ("Must be a number between 0 and 100")
Cancel = True
End If
End Sub
"Cancel = True" is used to keep the focus in the current field. So long as there is an error the user can not leave the TextBox. It also uses the Validate to validate if the data entry is a date before going further:
Code:
Private Sub txtDate_Validate (Cancel As Boolean)
If Not IsDate (txtDate.Text) Then
MsgBox ("Must be a valid date")
Cancel = True
End If
End Sub
Bookmarks