VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



IsNumber

by Matthew Inman (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

This routine was designed to act as a numbers-only mask for any TextBox Keypress event. Simply call it from any KeyPress event and feed it the KeyAscii return value.

Inputs
AsciiCode - This is the ascii code of the character to be tested.
Assumes
HOW TO CALL: In the KeyPress event of Text1 (just an example), all you need is If Not IsNumber(KeyAscii) then KeyAscii=0 and the text box will accept only numbers from the user while allowing them to use BACKSPACE.
Code Returns
Returns TRUE if the ascii code was of a numeric character OR backspace (saves time...you'll see), FALSE if not.
API Declarations




Rate IsNumber

Function IsNumber (ByVal KeyAscii As Integer) As Integer
If InStr(1, "1234567890", Chr$(KeyAscii), 0) > 0 Or KeyAscii = 8 Then
  IsNumber = True
Else
  IsNumber = False
End If
End Function

Download this snippet    Add to My Saved Code

IsNumber Comments

No comments have been posted about IsNumber. Why not be the first to post a comment about IsNumber.

Post your comment

Subject:
Message:
0/1000 characters