I’m new to Visual Basic 6, so please be patient (and thorough with your answers).
I’m building a form and I need to check if the information entered in one of its fields is numeric, otherwise the program has to beep.
The field is part of an array of controls and it is named txtMyField(0)
Last thing in my code I’ve written:
Private Sub txtMyField_Change(Index As Integer)
If Not IsNumeric(txtMyField(0).Text) Then
Beep
End If
End Sub
I don’t know if this code is correct and I don’t how to call the Sub to use it in order to check the field’s value before inserting in database.
Thanks a lot for your help!
You can do this by using the Validate event. You need to ensure that the CausesValidation property is true, if it is then the Validate event will be raised for that control.
Your event might look something like this:
This would ensure that all the controls in your control array are numeric (given that their CausesValidation property is set to True at startup). If one of the controls is empty or contains non-numeric characters you will get a Beep when the control loses focus.
Note some things here