Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    KeyCode=88 is not a Capital X (A2k3sp1)

    Hi All,
    Ok it's a long story about why that I won't go into....
    When I am in a certain textbox only the 4 and 6 keys on the number pad should return values and those values should be a capital X (4) and capital Y (6). The following code does what I want, mostly, but it returns small case letters; i.e. x, y. (The other entries, KeyCode 8, 9, etc., are left as is for navigation.) This code is in the textbox KeyDown event.

    <pre>If Me!txtMyText = strMyString Then
    Select Case KeyCode
    Case 8
    KeyCode = 8 'Backspace
    Case 9
    KeyCode = 9 'Tab
    Case 13
    KeyCode = 13 'Enter
    Case 27
    KeyCode = 27 'Escape
    Case 46
    KeyCode = 46 'Delete
    Case 100
    KeyCode = 88 'X
    Case 102
    KeyCode = 89 'Y
    Case Else
    KeyCode = 0
    End Select
    Else
    'do nothing
    End If
    </pre>

    What am I missing? Have I mis-translated the codes? or have I got a setting wrong?
    Thank you.

    gdr
    ---
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: KeyCode=88 is not a Capital X (A2k3sp1)

    The KeyCode argument is NOT an Ascii code. As the name indicates, it is a code for the key depressed by the user. Whether the user wants to type an x or an X, the same key is used.
    The On Key Down event also has a Shift argument. This tells you whether the Ctrl, Shift and/or Alt keys were down. Shift can be a combination of acCtrlMask, acShiftMask and acAltMask. To check if only the Shift key was down, test for Shift = acShiftMask. To test if the Shift key was down, possibly in combination with other modifier keys, test for Shift And acShiftMask = acShiftMask.

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: KeyCode=88 is not a Capital X (A2k3sp1)

    As Hans pointed out, KeyCodes and KeyAscii are two different things. KeyCodes can most easily be compared by using the built in VB key constants like vbKeyBack, vbKeyTab, vbKeyDelete, vbKeyEscape, vbKeyReturn, vbKeyX and vbKeyY. May I point out, however, that none of these have anything to do with the number pad keys, assuming you're talking about the number pad on an extended keyboard.
    Charlotte

  4. #4
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: KeyCode=88 is not a Capital X (A2k3sp1)

    Hi Hans,
    Thank you.
    That certainly explains why I had such a devil of a time trying to get this to work.
    I had never run across or done this before and your explanation has clarified the "codes" for me.

    gdr
    ---
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  5. #5
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: KeyCode=88 is not a Capital X (A2k3sp1)

    Hi Charlotte,
    Yes I was talking about the numberpad, which added to my confusion in reconciling the ascii codes to the key codes.
    The people I am doing this for thought it was too big of a keyboard stretch......all the other data entry, save for this 1 textbox is numeral and the only characters which are to be entered are X and Y.
    Thanks for your explanation. Between yours and Han's replies, I doubt if I will be able to get them confused again.
    Thank you.

    gdr
    ---
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •