Home All Groups Group Topic Archive Search About
Author
31 Aug 2010 5:51 PM
John Simpson
Help!!!

Windows 7, VB6

I have the following code with a mysterious problem. Hitting
keys A thru Z or numbers 0 thru 9, assign the correct results
the variable ch below. Punctuation is wrong. For example, the
/ key returns a keycode of 191.

I'm sure there is a simple fix, but it eludes me!

'
'
'
Private Sub rtbDesc_KeyDown(KeyCode As Integer, Shift As Integer)
    Static keyStroke               As Long
    Dim sp                         As Long
    Dim ch                         As String * 1

    If KeyCode <> 8 Then                         ' don't count the BS
        keyStroke = keyStroke + 1                ' count keystrokes
    Else                                         ' if it is a BS then
        keyStroke = keyStroke - 1                ' decrement the count
    End If

    If keyStroke > 60 And KeyCode = 32 Then      ' if more than 60
        rtbDesc.text = rtbDesc.text & vbCrLf     ' characters and a space
        sp = Len(rtbDesc.text)                   ' append a crlf to the
        rtbDesc.SelStart = sp                    ' text string and
        lineLength = sp
        keyStroke = 0                            '
    End If                                       '

    If KeyCode = 10 Or KeyCode = 13 Then
        keyStroke = 0
        lineLength = 0
        tmptext = ""
    Else
        lineLength = lineLength + 1
        ch = Chr$(KeyCode)
        tmptext = tmptext & ch
    End If

    Text1.text = KeyCode & "  " & Str(lineLength) & "  " & tmptext

    If Len(tmptext) < 30 Then
        flxDesc.Clear
        DoEvents
        DisplayText tmptext, Len(tmptext)
    End If

End Sub

Thanks is advance.

John

Author
31 Aug 2010 6:01 PM
Jeff Johnson
"John Simpson" <jasimp.nospam@earthlink.net> wrote in message
news:i5jfe7$5lt$1@news.eternal-september.org...

> Windows 7, VB6
>
> I have the following code with a mysterious problem. Hitting
> keys A thru Z or numbers 0 thru 9, assign the correct results
> the variable ch below. Punctuation is wrong. For example, the
> / key returns a keycode of 191.
>
> I'm sure there is a simple fix, but it eludes me!

There is a big difference between KeyCode (the parameter to KeyDown/Up) and
KeyAscii (the parameter to KeyPress). There are all sorts of keycodes
assigned to different keys on your keyboard. The / down by the shift key has
a different code than the / on the numeric keypad, because they are two
physically different keys. You can't count on a keycode paralleling the
ASCII code for the character on the key; the ASCII code is retrieved from a
map.

This has nothing to do with Windows 7, by the way, and should happen on any
OS.

Check out the vbKey* constants. You can find them via Intellisense or in the
Object Browser in the <globals> section of the VBRUN library.
Author
31 Aug 2010 6:24 PM
John Simpson
Show quote Hide quote
"Jeff Johnson" <i.get@enough.spam> wrote in
news:i5jg0u$b85$1@news.eternal-september.org:

> "John Simpson" <jasimp.nospam@earthlink.net> wrote in message
> news:i5jfe7$5lt$1@news.eternal-september.org...
>
>> Windows 7, VB6
>>
>> I have the following code with a mysterious problem. Hitting
>> keys A thru Z or numbers 0 thru 9, assign the correct results
>> the variable ch below. Punctuation is wrong. For example, the
>> / key returns a keycode of 191.
>>
>> I'm sure there is a simple fix, but it eludes me!
>
> There is a big difference between KeyCode (the parameter to
> KeyDown/Up) and KeyAscii (the parameter to KeyPress). There are all
> sorts of keycodes assigned to different keys on your keyboard. The /
> down by the shift key has a different code than the / on the numeric
> keypad, because they are two physically different keys. You can't
> count on a keycode paralleling the ASCII code for the character on the
> key; the ASCII code is retrieved from a map.
>
> This has nothing to do with Windows 7, by the way, and should happen
> on any OS.
>
> Check out the vbKey* constants. You can find them via Intellisense or
> in the Object Browser in the <globals> section of the VBRUN library.
>
>
>

Jeff,

I'm aware of all of the above, but how do I resolve this problem???

I mentioned Windows 7, because I always try to define the environment
before I post the question.

Thanks.

John
Author
31 Aug 2010 7:32 PM
ralph
On Tue, 31 Aug 2010 18:24:10 +0000 (UTC), John Simpson
<jasimp.nospam@earthlink.net> wrote:


>
>I'm aware of all of the above, but how do I resolve this problem???
>
>I mentioned Windows 7, because I always try to define the environment
>before I post the question.
>

Perhaps KeyPress() would be more useful?

Note: You are usually better off to do any processing in a "Key Up" or
"Key Press" and use "Key Down" to set flags for combinations, ie,
Ctrl+A, Shift+Tab, ...

But that is just general advise and can be safely ignored. <g>

-ralph
Author
1 Sep 2010 7:12 PM
John Simpson
ralph <nt_consultin***@yahoo.net> wrote in
Show quoteHide quote
news:bolq7651l94avknmt7hmea5ft88qve9ean@4ax.com:

> On Tue, 31 Aug 2010 18:24:10 +0000 (UTC), John Simpson
> <jasimp.nospam@earthlink.net> wrote:
>
>
>>
>>I'm aware of all of the above, but how do I resolve this problem???
>>
>>I mentioned Windows 7, because I always try to define the environment
>>before I post the question.
>>
>
> Perhaps KeyPress() would be more useful?
>
> Note: You are usually better off to do any processing in a "Key Up" or
> "Key Press" and use "Key Down" to set flags for combinations, ie,
> Ctrl+A, Shift+Tab, ...
>
> But that is just general advise and can be safely ignored. <g>
>
> -ralph
>

Thanks Ralph. KeyPress works. That's what I had to begin with, but
I changed it for some reason. God, how I hate these senior-moments!

John