They perform **identically**. The vbKeyLeft is a predefined constant and
it's value is 37. You use it just as you would use any number. When you
use 37, you have to provide a comment to explain what that value stands
for. When you use vbKeyLeft, it's value is the same 37 (try Print
vbKeyLeft in the Immediate window) and it is self commenting. To see the
rest of the predefined KeyCode constants, go into the VB Help files and
type "Keycode constants" (without the quote marks).
> Hi George
> Thanks for that, that works very well.
> The way I was trying to do it was similar, But harder. My way I had to
find the
> number for each key on the keyboard. But using the vbKey command has
to be the
> way for me.
> To find the number value for each key I used this code.
> Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
> Label1.Caption = KeyCode
> End sub
> This gave me the number for each key, for example vbKeyUp = 38,
vbKeyDown =
> 40
> So using your code
> Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
> Select Case KeyCode
> Case 37 'vbKeyLeft
> MsgBox "You have clicked the LEFT arrow."
> Case 39 'vbKeyRight
> MsgBox "You have clicked the RIGHT arrow."
> Case 38 'vbKeyUp
> MsgBox "You have clicked the UP arrow."
> Case 40 'vbKeyDown
> MsgBox "You have clicked the DOWN arrow."
> End Select
> End Sub
> Many thanks to all, any comments always welcome
> Steve Pearson
> >Steve
> >Use a named literal for the key code.
> >try this
> >1 form
> >this code
> >Private Sub Form_KeyDown(KeyCode As Integer, _
> >Shift As Integer)
> >Select Case KeyCode
> >Case vbKeyLeft
> >MsgBox "You have clicked the LEFT arrow."
> >Case vbKeyRight
> >MsgBox "You have clicked the RIGHT arrow."
> >Case vbKeyUp
> >MsgBox "You have clicked the UP arrow."
> >Case vbKeyDown
> >MsgBox "You have clicked the DOWN arrow."
> >End Select
> >End Sub
> >HTH
> >George
> >> Hello all
> >> Can some kind soul please tell me the KeyAscii code (number) for
the 4
> >arrow
> >> keys under the delete end & page down keys. I would like to use
them in a
> >> KeyPress sub.
> >> Many thanks
> >> Steve Pearson