David,
One option is to perform input validation in the textbox’s Validating event.
When the user changes the focus from a textbox (or other control) the
textbox’s Validating event occurs.
In the Validating event you can write code to validate the data in the
textbox. If the user has entered invalid data you can inform the user and
cancel the Validating event.
Canceling the textbox’s Validating event prevents the focus from leaving the
textbox. This forces the user to enter good data into the textbox in order to
continue.
For example, in the txtLength textbox’s Validating event you can test for
invalid input like this:
Private Sub txtLength_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles txtLength.Validating
'If the text in the txtLength textbox is not numeric
If Not IsNumeric(txtLength.Text) Then
'Inform the user that length must be a number
MsgBox("Length must be a number", _
MsgBoxStyle.Exclamation, "Input Error")
'Cancel the Validating event
'to prevent the focus from changing
e.Cancel = True
End If
End Sub
Another option is to perform input validation in a textbox’s Validating
event. But instead of using a message box to display error conditions, use an
ErrorProvider control.
An ErrorProvider control provides an unobtrusive graphical display that a
control contains invalid data.
Kerry Moorman
"David" wrote:
Can anyone point me in the right direction. I am tring to ensure that the
user input in a textbox is a Number.
Any help would be great
Thanks
God Bless