|
-
Oct 28th, 2000, 03:56 PM
#1
Thread Starter
Lively Member
How can I make is so that a user can only enter numbers in text boxes?
Thanks
-
Oct 28th, 2000, 04:00 PM
#2
-
Oct 28th, 2000, 09:53 PM
#3
That threads got about a million different ways fo doing it.
Basically, in the KeyPress event, decide if it's a character you want or not, and if it's not, set KeyAscii = 0
eg:
Code:
Select Case KeyAscii
Case 48 To 57 'Numbers
Case 46 ' . (period)
Case 8 ' Backspace
Case 10 'Linefeed
Case 13 'Carriage return
Case Else
KeyAscii = 0
End Select
Other interesting ascii values you might want to look for are Ascii 3, 22 and 26. These equate to Ctrl-C, Ctrl-V and Ctrl-X.
Assuming you handle the Ctrl characters, the only other way to put text into the text box is right clicking and pasting, in which case you need to check the TextBox_Change event and remove any non numeric characters.
Remember to keep the cursor at the current location (nothing annoys users more than a seemingly random moving cursor)
And 10 points to anyone who can tell me why the ctrl characters come through as those three ascii values (which officially aren't used by Windows). It's a particularly ingenious reason.
- gaffa
-
Oct 29th, 2000, 07:37 AM
#4
Frenzied Member
Basicly, it's a good thing to let all the ASCII values < 33 trough, because that are the 'system' characters (space, tab(?), enter, ctrl... etc)
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|