VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A very simple way to require numbers only in a text box.

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.

Rate 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

Download this snippet    Add to My Saved Code

A very simple way to require numbers only in a text box. Comments

No comments have been posted about A very simple way to require numbers only in a text box.. Why not be the first to post a comment about A very simple way to require numbers only in a text box..

Post your comment

Subject:
Message:
0/1000 characters