# Visual Basic > Visual Basic 6 and Earlier >  Tabs

## afbille

I have a form with 3 textboxes on i. txt1, txt2 and txt3. I would like to know if I fill the txt1 with 2 digits, what would be the code to have the cursor tab to the next textbox.

----------


## Elroy

```

Private Sub txt1_Change()
    If Len(txt1.Text) = 2 Then txt2.SetFocus
End Sub


```

Something like that?

----------


## afbille

Thar worked. Thanks

----------


## SamOscarBrown

BUT.....if you were to start using arrays of textboxes, it could look like this:



```
Private Sub Txt1_Change(Index As Integer)
    If Index = Txt1.ubound Then Exit Sub
    If Len(Txt1(Index).Text) = 2 Then Txt1(Index + 1).SetFocus
End Sub
```

this checks to see how many textboxes named Txt1 in an array of them...and when it reaches that last one, it exits.

EDIT...if you set the maxlength of your highest numbered textbox in the array to 2 (in the IDE), then you will have ALL textboxes with 2 values.
BUT, if you go back to any of the other textboxes which already have two characters in them and type in something else, you will end up with one (or more) with more than 2 characters.
Best to set the maxlength of ALL your txt1 textboxes to 2 in the IDE.  They you won't have an issue. whether you use arrays or not

----------

