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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanku guyz, for ur fast and to the point explanations..
KeyCode allows you see whats been pressed.
KeyAscii gives you the character that's been pressed and allows you to change it.