Results 1 to 13 of 13

Thread: Stop Letters being entered into a Text Box

Threaded View

  1. #5
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Well if you know how to stop numbers, you know how to stop letters!

    Code:
    'stop numbers
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      If (IsNumeric(Chr(KeyAscii))) Then KeyAscii = 0
    End Sub
    Code:
    'stop letters
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      If Not (IsNumeric(Chr(KeyAscii))) Then KeyAscii = 0
    End Sub
    This does't remove all the other possible characters, such as puntuation and control characters.
    But you can check for the values between 0 and 58 and then over 122 and simply eliminate them.
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      If KeyAscii > 0 or KeyAscii < 58 Then 
            KeyAscii = 0
      Else
           If KeyAscii > 122 Then KeyAscii = 0
      EndIf
    End Sub
    This will give you only letters.

    The numbers are the decimal Ascii number corresponding to the character. 32 is a space.
    See your VB help, there is an Ascii chart in it.
    Last edited by dsy5; Feb 11th, 2001 at 01:47 PM.
    Donald Sy - VB (ab)user

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