DavidGreenfield
asked on
Chr(Key) - Numeric Keypad
Hi there
I have a string of allowed characters ... i.e. "0123456789ABCD"
depending on the characters in the string depends on what the user is allowed to enter into the text box.
If Len(AcceptCharacters) > 0 Then
If InStr(1, AcceptCharacters, Chr(Key)) = 0 Then
FilterKeypress = 0
Beep()
End If
end if
however this does not work for the numeric key pad as the characters being returned bear no resemblemence to 0123456789 (i.e I get abcd etc). How can I do this ... I know you can do isnumeric ... but I need to be allow the user to just pass "345YH" etc, so I really need to be able to get the proper character being entered, i.e. 0123456789
Thanks!
I have a string of allowed characters ... i.e. "0123456789ABCD"
depending on the characters in the string depends on what the user is allowed to enter into the text box.
If Len(AcceptCharacters) > 0 Then
If InStr(1, AcceptCharacters, Chr(Key)) = 0 Then
FilterKeypress = 0
Beep()
End If
end if
however this does not work for the numeric key pad as the characters being returned bear no resemblemence to 0123456789 (i.e I get abcd etc). How can I do this ... I know you can do isnumeric ... but I need to be allow the user to just pass "345YH" etc, so I really need to be able to get the proper character being entered, i.e. 0123456789
Thanks!
Use keyup event and use e.KeyValue in vent, it will return you keyascii and that will do the work for you
ASKER
sorry I should have put the code in i am calling aswell. I am already using the keyup event and the e.keyvalue ... basically chr(e.keyvalue) is not returning 0123456789 as I want.
type 1 in numeric keypad =-> chr(e.keyvalue) = a
type 2 in numeric keypad =-> chr(e.keyvalue) = b
type 3 in numeric keypad =-> chr(e.keyvalue) = c
Private Sub TextBox1_Keyup(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv entArgs) Handles TextBox1.KeyDown
'Validate characters being entered
If FilterKeypress(e.KeyValue, "1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ ") = 0 Then e.SuppressKeyPress = True
End Sub
type 1 in numeric keypad =-> chr(e.keyvalue) = a
type 2 in numeric keypad =-> chr(e.keyvalue) = b
type 3 in numeric keypad =-> chr(e.keyvalue) = c
Private Sub TextBox1_Keyup(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEv
'Validate characters being entered
If FilterKeypress(e.KeyValue,
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.