Solved

trapping arrow keys

Posted on 1998-08-20
2
200 Views
Last Modified: 2011-10-03
I would like the user to be able to use the arrow keys to manuver around a series of textboxes.
But I can't find the appropriate Ascii codes for them.
How can I let the user move around my program by just using the arrow keys?
With code please...
This is in VB4-16bit.
0
Comment
Question by:dtucker
2 Comments
 
LVL 1

Accepted Solution

by:
blwatkins earned 100 total points
ID: 1430071
In the KeyDown Event you can evaluate the KeyCode value to
see what key was pressed such as:

Private Sub Grid1_KeyDown(KeyCode As Integer, Shift As Integer)
  Select Case KeyCode
    Case 39   ' Right
      'Do Code for Moving Right
    Case 37   ' Left
      'Do Code for Moving Left
    Case 38   ' UP
      'Do Code for Moving UP
    Case 40   ' Down
      'Do Code for Moving Down
  End Select
End Sub


You can also use the VB Predefind values (I'm not sure if thay are available in VB4-16, but if so, it makes the code look a little better, and is easier to read.  (vbKeyUP, vbKeyDown, vbKeyRight, vbKeyLeft).


0
 
LVL 4

Expert Comment

by:mcix
ID: 1430072
Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
   
    Select Case KeyCode
   
        Case 37
            ' Left Arrow
        Case 38
            ' Up Arrow
        Case 39
            ' Right Arrow
        Case 40
            ' Down Arrow
    End Select
   
End Sub

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now