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

  • Thread starter Thread starter Richard Buttrey
  • Start date Start date
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
 
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
 
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

..
 
Back
Top