Reference Controls to chang attributes through Array

D

DanB

I have 3 CommandButton controls (cmd_1, cmd_2, ... cmd_10)

I want to be able to cycle through them to change their attributes using
data stored in an array cb(10). I know I'm missing something simple, but
integral. Can anyone help?

I've tried:

Dim myObj as Object
Dim x as Interger

For x = 1 to 10

Set myObj = "cmd_" & x
With myObj
.Visible = cb(x)
End With

Next x
 
D

Dave Peterson

On a worksheet?

dim x as long 'watch your spelling of integer
with activesheet
for x = 1 to 10
.oleobjects("cmd_" & x).visible = cb(x)
next x
end with

cb() is an array of true/falses, right.

Ps. I'd use:
dim CB(1 to 10) as boolean

dim CB(10) as boolean
will create an array of 11 elements--0 to 10.
(unless you're using an "Option Base" statement.)
 
D

DanB

Sorry Dave,

I meant on a UserForm.

I already have cb() as Boolean in Public declarations.

Any thoughts?

Dan
 
D

Dave Peterson

Dim x As Long 'watch your spelling of integer
For x = lbound(cb) to ubound(cb) 'better than hardcoding the numbers
Me.Controls("cmd_" & x).Visible = cb(x)
Next x


And when I used lbound() and ubound(), you'll have to use: dim cb(1 to 10), not
just cb(10).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top