Range of control arrays

What is the most efficient way to loop through a set of control arrays to find out the range of index values?

I want to set the caption on each button on the form from a database. The database is indexed on the control arrays index. I need to know if the controls on a particullar form ranges from lets say 42 through 77 and only look up those values.
DPProAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amebaCommented:
' add control array of 2 command buttons, paste this code
Option Explicit

Private Sub Form_Click()
    Dim ctl As Control
    For Each ctl In Command1
        Print ctl.Index
    Next
End Sub
0
KurvyCommented:
Control.Lbound
Control.Ubound

These two properties should give you the information
0
caraf_gCommented:
Dim objControl As Control

For Each objControl In Controls
    If objControl.Name = "YourControlArraysName"
        If (objControl.Index >= 42) And (objControl.Index >= 77) Then
            'do something
        End If
    End If
Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

James_stillmanCommented:
If i understand correctly. You might want to try the control array base name (without the (index)) and then use

..ubound = upper bound
..lbound = lower bound
..count = total number of coontrols in array

Hope this helps

Cheers

James
0
amebaCommented:
set caption:
    Me.Controls("Command1", "42").Caption = "Hello"
0
caraf_gCommented:
Buggy code... sorry

+ another way to set caption.

Dim objControl As Control

For Each objControl In Controls
    If objControl.Name = "YourControlArraysName" Then
        If (objControl.Index >= 42) And (objControl.Index <= 77) Then
            'do something
            'for example
            objControl.Caption = "Hello"
        End If
    End If
Next

0
amebaCommented:
  objControl.Caption = "A C B B A A B A C C"  ' :(
0
caraf_gCommented:
objControl.Text = "13/14"
>:-(

This is where I have to comment:
DPPro. If you're in ANY way dissatisfied with my answer, even if you think it's too obvious or something... just reject it. PLEASE just reject it.

;-)
0
caraf_gCommented:
DPPro, didn't I just ask you to please REJECT my answer if you were in any way dissatisfied with it?

If my answer is not clear or needs more explanation, I would have been happy to explain it further. Instead, you give me a "B".

I think I'll be putting you on my blacklist.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.