Determining the index of current control in array

I have 2 arrays - one holding a "beginning" 9 digit number, the other holding an ending 9 digit number.  When the user hits ENTER or TAB, I would like the first 7 digits from the beginning number to appear in the ending number box.  I can make the code work if I use individual textboxes but since this is an array, it's a bit different.  How do I determine the item number of my current control in the array?  What I would like is this:

Beginning                      Ending
123456789 - HIT TAB OR ENTER - 1234567
998879988 - HIT TAB OR ENTER - 9988799
SilveyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CJ_SConnect With a Mentor Commented:
Create 2 textboxes with the same name (Text1)
Create another 2 textboxes with the same name (Text2)

Add the following code to your application:

Private Sub Text2_GotFocus(Index As Integer)
    Text2(Index).Text = Left(Text1(Index).Text, 7)
End Sub

Regards,
CJ
0
 
prashant_n_mhatreCommented:
Which langauge man? VB?
0
 
SilveyAuthor Commented:
Visual Basic - SORRY!
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
SilveyAuthor Commented:
Visual Basic - SORRY!
0
 
Z_BeeblebroxCommented:
I don't understand. Do you have a control array, a numeric array, or both? If you have a control array, the index of the control will be given to you in the event parameters, eg Text1_LostFocus(Index As Integer).

Zaphod.
0
 
CJ_SCommented:
Can you make a small list of what element are on the screen, what kind of array you have, and where the data is actually coming from. That will help quite a bit...

Regards,
CJ
0
 
SilveyAuthor Commented:
I have 2 arrays of textboxes; array 1 = BEGINNINGIDs, array 2 = ENDINGIDs.  The user keys a "beginning id" which is a 9 digit number then hits TAB or ENTER (which takes them to the ending id box).  After entering the beginning id, when the user hits ENTER or TAB, I would like the first 7 digits from the beginning id to appear in the ending id box.
0
 
SilveyAuthor Commented:
Thank you, CJ!  I thought that I had to explicitly reference the index...I didn't realize that just using INDEX was sufficient!
0
 
CJ_SCommented:
Glad to be of service!

Regards,
CJ
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.