Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get user input from a Keyboard

Status
Not open for further replies.

campbere

Technical User
Oct 10, 2000
146
US
I have a screen with command buttons labeled 1 2 3
and label descriptions to the side. I would like to give the user the option of pressing the command button, file menu, or just hitting the number on the keyboard. I have the first two options taken care but cant get the third. How do I get the the program to respond to a user that types in 1, 2, or 3?

Thanks
 
Use a Function based on Key pressed .. then in a Select case tell it what you want it to do.


Joanne
 
Set your form's KeyPreview property to TRUE. Add code to the forms KeyPress event...

Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 49
'Call subroutine for command button 1
Case 50
'Call subroutine for command button 2
Case 51
'Call subroutine for command button 3
End Select
End Sub

OR

Private Sub Form_KeyPress(KeyAscii As Integer)
Select Case chr$(KeyAscii)
Case "1"
'Call subroutine for command button 1
Case "2"
'Call subroutine for command button 2
Case "3"
'Call subroutine for command button 3
End Select
End Sub


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top