by Mike Reed (4 Submissions)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Tue 23rd May 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
A very simple way to require numbers only in a text box.
'Making sure user enter a number 15 thur 600
Dim TestInput As Integer 'Will set for numbers only
On Error GoTo Inputwrong 'On error will goto a message.
TestInput = txtCmdMin.Text
If TestInput < 15 Or TestInput > 600 Then
MsgBox "Invalid number, Please re-enter a number 15 thru 600!", , "Your title"
txtCmdMin.SetFocus
SendKeys "{Home}+{End}"
Exit Sub
End If
Inputwrong: 'If the user input was anything but a number this will display.
If Err.Number = 13 Then
MsgBox "Invalid number, Please re-enter a number 15 thru 600!", , "Your title"
txtCmdMin.SetFocus
SendKeys "{Home}+{End}"
Exit Sub
End If
End Sub