Link to home
Start Free TrialLog in
Avatar of rjef
rjefFlag for United States of America

asked on

textbox array setfocus to next text box

i am using vb6 and I have a textbox array and  I want to set focus to the next text box in the array when the user hit enter or tab
ie

Private Sub arrayText_KeyPress(Index As Integer, KeyAscii As Integer)
If KeyAscii >= 97 And KeyAscii <= 122 Then
    KeyAscii = KeyAscii - 32
End If

If KeyAscii = 9 Or KeyAscii = 13 Then
arrayText(I).SetFocus = True  
End If

End Sub

how do i know what i is?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rjef

ASKER

like this-

should 'i' have a value?

Private Sub arrayText_KeyPress(Index As Integer, KeyAscii As Integer)
On Error Resume Next
arrayText(Index + 1).SetFocus
If Err.Number <> 0 Then
    arrayText(0).SetFocus
End If
On Error GoTo 0
If KeyAscii >= 97 And KeyAscii <= 122 Then
    KeyAscii = KeyAscii - 32
End If

If KeyAscii = 9 Or KeyAscii = 13 Then
arrayText(I).SetFocus = True
End If

End Sub
Avatar of rjef

ASKER

I got it
Private Sub arrayText_KeyPress(Index As Integer, KeyAscii As Integer)

If KeyAscii >= 97 And KeyAscii <= 122 Then
     KeyAscii = KeyAscii - 32
 End If
 If KeyAscii = 9 Or KeyAscii = 13 Then
On Error Resume Next
arrayText(Index + 1).SetFocus
If Err.Number <> 0 Then
    arrayText(0).SetFocus
End If
On Error GoTo 0
End If

End Sub
Avatar of rjef

ASKER

thanks
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2018
              Experts Exchange Top Expert VBA 2018