Link to home
Start Free TrialLog in
Avatar of wide-eyes
wide-eyes

asked on

key disabling

hello

I'm new to VB programming.

I want to block any non-digit entries into a textbox.
It will work fine if i depend upon keypress event. For example,

Private Sub Text1_KeyPress(KeyAscii As Integer)

Select Case KeyAscii
   Case 48 To 57
     'Allow keystroke
   Case Else
      KeyAscii = 0
End Select

End Sub

But, if I try keydown event it won't work.

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
   
   Select Case KeyCode
      Case vbKey0 To vbKey9
         'Allow the key stroke
      Case Else
         KeyCode = 0
   End Select

End Sub

The question is, Why? Whats lacking in keydown?

ASKER CERTIFIED SOLUTION
Avatar of JR2003
JR2003

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JR2003
JR2003

The difference is between KeyCode and KeyAscii.
KeyCode allows you see whats been pressed.
KeyAscii gives you the character that's been pressed and allows you to change it.
Avatar of wide-eyes

ASKER


Thanku guyz, for ur fast and to the point explanations..