Solved

Tabindex

Posted on 2001-06-08
9
712 Views
Last Modified: 2007-11-27
Hi all
I have a few textbox controls on a form and I want to use the arrow keys to navigate around the form.  The boxs are aligned so that when the user presses the right arrow key,tab is invoked.  Left is a tab backwards effect. These work ok.  However when the user presses on the up arrow they may have to jump 3 tabindexes backwards.  the code I have is as follows

x is read in as the index of the box we are leaving

dim ctl as control

        For Each ctl In Controls
            If TypeOf ctl Is TextBox Then
                If ctl.tabindex = x Then
                    ctl.tabindex = x - 3
                    ctl.SetFocus
                End If
            End If
        Next


This does not work as expected (probably wrong).  Does anybody have any suggestions.  Also why doen't the tab index word take small letters as if it is an incorrect
property.


regards Botch.
0
Comment
Question by:Botch
9 Comments
 
LVL 7

Expert Comment

by:Joe_Griffith
ID: 6168022
Resetting the tabindex in code is probably not a good idea.  For one thing two controls can't have the same tabindex (that is probably what is happening here).  I think you should find another way to identifiy the controls.  If they are all the same (text boxes for instance) you should have them in an array.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6168024
If you have an array of textbox controls then all you need to do is this:

txtMyTextBox(x - 3).SetFocus
0
 
LVL 1

Expert Comment

by:nikelsh
ID: 6168095
use this one

Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
on error goto err:
Select Case KeyCode
   
   Case 37
         Text1(Index - 1).SetFocus
       
   Case 39
         SendKeys "{tab}"
End Select
exit sub
err:

End Sub


nikelsh
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6168562
And why doesn't it "recognize" tabindex (by capitalizing it)?

The answer is that you are redirecting the control into a generic container which has no prior knowledge of the control.  As such it doesn't recognize the tabindex property at design time.  At run-time, the control container picks up the characteristics of the textbox and THEN recognizes tabindex as a valid property.

0
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.

 
LVL 9

Accepted Solution

by:
Valliappan AN earned 50 total points
ID: 6172765
Setting the tabindex wont work, as you have done. Since it will overlap with another control with the tabindex with which you set, or else, you need to set the proper tab index affecting the tabindex range that you set.

I mean, I suppose VB does not set the tabindex in runtime automatically as in design time when you change the tabindex for one control, if tabindex lies inbetween another control's tabindex.

A better way is to use SendKeys, like,

if you wish to move 3 tabindexes backwards,

use,

Sendkeys "+{TAB}+{TAB}+{TAB}"

If you wish to move front 3 tabindexes do,

Sendkeys "{TAB}{TAB}{TAB}"

hope it helps.
Cheers.
0
 
LVL 2

Expert Comment

by:Microsoft
ID: 6174772
HMMM Interesting, I think im gonna agree with Valli, I dont agree with the method and there should be an easier way but because the way that VB handles this key and you cannot cross with another control and the same time his method would be far more safer and less confusing at debug time so im gonna suggest
:-

Sendkeys "+{TAB}+{TAB}+{TAB}"

If you wish to move front 3 tabindexes do,

Sendkeys "{TAB}{TAB}{TAB}"

thats the only safe way to get around this problem without having to worry about any other control

Many Thanks

Mr Microsoft him self.
:op
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6176200
Botch, please respond to this thread.
0
 

Author Comment

by:Botch
ID: 6176292
Thanks for that vialli.  Thats works.
So when I clickon the up arrow the program tabs back 3.  When I click on the up arrow the program tabs up three.
I also tried the other suggestions and its true to say tht if the textboxes are an array the following seems to work
for the up arrow

Dim ctl As Control
    If keycode = 38 Then
        For Each ctl In Controls
            If TypeOf ctl Is TextBox Then
                If ctl.TabIndex = tabidx and tabidx<3 then
                    ctl.TabIndex = tabidx - 3
                    ctl.SetFocus
                ElseIf y < 3 Then
                    ctl.TabIndex = 0
                    ctl.SetFocus
                End If
            End If
        Next
    End If

The sendkeys way is nicer though.  Thanks everybody for all the help.
regards
botch

0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6176412
thanks botch and you are welcome for further comments if need be.

Cheers.
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

Title # Comments Views Activity
VB6 add a minute to the date time value 8 61
Vb.net 2008 2 56
VB6 code to programmatically convert pdf to excel 21 67
MS Access - Capture pressed key onclick 4 28
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

919 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

16 Experts available now in Live!

Get 1:1 Help Now