Using Loop Counter index for the last character of a forms object.

R

Richard Buttrey

Good morning.

In the initalisation event of a form I have several labels and list boxes
for which I want to set various properties. For instance
Label1.visible=False, Label2.visible=False.

I realise I can list them individually, but it would be neater if I could
just refer to the label number with a loop counter.

e.g. For x=1 to6
Label(x).Visible=False
Next x

But I can't seem to find the right syntax. The above doesn't work.

Any ideas please. Usual TIA

Richard
 
J

Jim Cone

Richard,
Why not set the properties when you design the form?
However, this syntax may work for you...
'--
Private Sub UserForm_Initialize()
Dim n As Long
For n = 1 To 3
Me.Controls("label" & n).Caption = n * n
Next
End Sub
'--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Richard Buttrey"
wrote in message
Good morning.
In the initalisation event of a form I have several labels and list boxes
for which I want to set various properties. For instance
Label1.visible=False, Label2.visible=False.
I realise I can list them individually, but it would be neater if I could
just refer to the label number with a loop counter.

e.g. For x=1 to6
Label(x).Visible=False
Next x

But I can't seem to find the right syntax. The above doesn't work.
Any ideas please. Usual TIA
Richard
 
R

Richard Buttrey

Thanks for the prompt response Jim,

I'll give it a whirl.

The reason I need to do it is that I change the properties, in particular
the visible property, in the course of the application, so setting them
during the form design would only last so long.

Kind regards,

Richard

..
 

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