For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > August 2005 > Learning More About Keystrokes!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Learning More About Keystrokes!
Arpan

2005-08-28, 3:55 am

A VB6 Form has, say, 4 buttons with the captions 1, 2, 3 & 4. When the
user clicks button 1, a label displays 1. When the user clicks button
2, the label displays 2, so on & so forth. Now I want to give my users
the option to use the keyboard as well to enter values in the label.
For e.g. when the user presses '1' (or Num 1) on the keyboard, the
label should display 1. When the user presses '2' (or Num 2) on the
keyboard, the label should display 2.

How do I do this? Can someone refer a few websites where I can get help
on this topic?

Thanks,

Arpan

Ted

2005-08-28, 3:55 am

Set the form KeyPreview property to True

In the form KeyUp

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
'Keyboard Top row keys
Case vbKey0
Label1.Caption = "0"
Case vbKey1
Label1.Caption = "1"
Case vbKey2
Label1.Caption = "2"
Case vbKey3
Label1.Caption = "3"
Case vbKey4
Label1.Caption = "4"
Case vbKey5
Label1.Caption = "5"
Case vbKey6
Label1.Caption = "6"
Case vbKey7
Label1.Caption = "7"
Case vbKey8
Label1.Caption = "5"
Case vbKey9
Label1.Caption = "9"


'Keys on the Numeric Keypad
Case vbKeyNumpad0
Label1.Caption = "0"
Case vbKeyNumpad1
Label1.Caption = "1"
Case vbKeyNumpad2
Label1.Caption = "2"
Case vbKeyNumpad3
Label1.Caption = "3"
Case vbKeyNumpad4
Label1.Caption = "4"
Case vbKeyNumpad5
Label1.Caption = "5"
Case vbKeyNumpad6
Label1.Caption = "6"
Case vbKeyNumpad7
Label1.Caption = "7"
Case vbKeyNumpad8
Label1.Caption = "5"
Case vbKeyNumpad9
Label1.Caption = "9"
End Select
End Sub

> How do I do this? Can someone refer a few websites where I can get help
> on this topic?

There 100s of websites with VB samples
http://www.freevbcode.com/default.asp
http://vbnet.mvps.org/
http://vb.mvps.org/
http://blackbeltvb.com/
http://www.vb-helper.com/howto.htm


"Arpan" <arpan_de@hotmail.com> wrote in message
news:1125203978.467583.94660@g43g2000cwa.googlegroups.com...
>A VB6 Form has, say, 4 buttons with the captions 1, 2, 3 & 4. When the
> user clicks button 1, a label displays 1. When the user clicks button
> 2, the label displays 2, so on & so forth. Now I want to give my users
> the option to use the keyboard as well to enter values in the label.
> For e.g. when the user presses '1' (or Num 1) on the keyboard, the
> label should display 1. When the user presses '2' (or Num 2) on the
> keyboard, the label should display 2.
>
> How do I do this? Can someone refer a few websites where I can get help
> on this topic?
>
> Thanks,
>
> Arpan
>



Mike L

2005-08-28, 6:55 pm

I agree with Ted except for:

> Case vbKey8
> Label1.Caption = "5"
> Case vbKeyNumpad8
> Label1.Caption = "5"


should be Label1.Caption = "8"... :-)


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com