Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Apr 2002
    Location
    United Kingdom
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ascii codes (VB6)

    Im trying to capture key presses in a text box and have noticed that the Ascii codes appear to be different in VB than they are in DOS. i.e. The * on the number pad returns 106, but the character for 106 is j. Would anyone have a list of the ascii code & characters used in VB? or have any idea why they are different?

  2. #2
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ascii codes (VB6)

    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

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

    Re: ascii codes (VB6)

    You need to distinguish between character codes (ASCII or ANSI) and key codes.

    The KeyPress event uses character codes: Private Sub object_KeyPress(KeyAscii As Integer). KeyAscii will have value 42 if you type a * and 106 if you type a j and 74 if you type a J.

    The KeyDown and KeyUp events use key codes: Private Sub object_KeyDown(KeyCode As Integer, Shift As Integer). Each key on the keyboard returns a unique key code; the Shift parameter provides information about the status of the Shift, Alt and Ctrl keys (and the mouse buttons). For the alphabet keys, the key code is the same as the ASCII code of the corresponding upper case letter, but there are key codes for keys that KeyPress doesn't handle, such as the function keys and navigation keys. Using KeyUp or KeyDown, you can distinguish between * on the numeric keypad and Shift+8.

    If you open the Object Browser (F2) and type vbkey in the search box, you'll see a list of all symbolic constants for the key codes. For instance, the key code for * on the numeric keypad is vbKeyMultiply = 106, and the code for the J key is vbKeyJ = 74. Whether you type lower case j or upper case J, the key code is vbKeyJ.

  4. #4
    New Lounger
    Join Date
    Apr 2002
    Location
    United Kingdom
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ascii codes (VB6)

    Thanks pieterse for the link to the ascii chart - very handy chart indeed and also thank you Hans for your info, I've now fixed the problem. <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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