954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do i test if a user enter a letter in a textbox?

the user should enter a digit instead??? what shall i use???

janeane_tho12n
Newbie Poster
10 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 

Try this:

Private Sub Text1_KeyPress(KeyAscii As Integer)

    Select Case KeyAscii
    Case 48 To 57
        ' These are acceptable keystrokes
    Case Else
        ' These are unacceptable, and should be ignored
        KeyAscii = 0
    End Select
    
End Sub

The numbers 48 to 57 are the ascii values of the numbers 0 to 9
more characters can be added.

i.e. 12,48 to 57,65,69 etc

Either single numbers or groups.

Pg

purplegerbil
Junior Poster in Training
78 posts since Apr 2005
Reputation Points: 24
Solved Threads: 6
 

it worked. thanks but when i press the backspace key it prompted me an error msg. why is that so?

janeane_tho12n
Newbie Poster
10 posts since May 2006
Reputation Points: 10
Solved Threads: 0
 
Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case 48 To 57
        ' These are acceptable keystrokes
    Case 8
        
    Case Else
        ' These are unacceptable, and should be ignored
        KeyAscii = 0
    End Select
    
End Sub
Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You