Link to home
Start Free TrialLog in
Avatar of DavidGreenfield
DavidGreenfieldFlag for United Kingdom of Great Britain and Northern Ireland

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!

Avatar of DEEPESH
DEEPESH

Use keyup  event and use e.KeyValue in vent, it will return you keyascii and that will do the work for you
Avatar of DavidGreenfield

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.KeyEventArgs) Handles TextBox1.KeyDown

        'Validate characters being entered
        If FilterKeypress(e.KeyValue, "1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ") = 0 Then e.SuppressKeyPress = True

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of vbturbo
vbturbo
Flag of Denmark image

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
SOLUTION
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
SOLUTION
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