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

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2006
Posts: 10
Reputation: janeane_tho12n is an unknown quantity at this point 
Solved Threads: 0
janeane_tho12n janeane_tho12n is offline Offline
Newbie Poster

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

 
0
  #1
May 8th, 2006
the user should enter a digit instead??? what shall i use???
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 75
Reputation: purplegerbil is an unknown quantity at this point 
Solved Threads: 6
purplegerbil's Avatar
purplegerbil purplegerbil is offline Offline
Junior Poster in Training

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

 
0
  #2
May 8th, 2006
Try this:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Text1_KeyPress(KeyAscii As Integer)
  2.  
  3. Select Case KeyAscii
  4. Case 48 To 57
  5. ' These are acceptable keystrokes
  6. Case Else
  7. ' These are unacceptable, and should be ignored
  8. KeyAscii = 0
  9. End Select
  10.  
  11. 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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 10
Reputation: janeane_tho12n is an unknown quantity at this point 
Solved Threads: 0
janeane_tho12n janeane_tho12n is offline Offline
Newbie Poster

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

 
0
  #3
May 8th, 2006
it worked. thanks but when i press the backspace key it prompted me an error msg. why is that so?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

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

 
0
  #4
May 8th, 2006
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Text1_KeyPress(KeyAscii As Integer)
  2. Select Case KeyAscii
  3. Case 48 To 57
  4. ' These are acceptable keystrokes
  5. Case 8
  6.  
  7. Case Else
  8. ' These are unacceptable, and should be ignored
  9. KeyAscii = 0
  10. End Select
  11.  
  12. End Sub
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC