Results 1 to 4 of 4

Thread: How to limit text box character entries to NUMBERS only??

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    84
    How can I make is so that a user can only enter numbers in text boxes?

    Thanks

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

  3. #3
    Guest
    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

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    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
  •  



Click Here to Expand Forum to Full Width