declaring an array

G

Guest

I have a form with 10 labels, and a module for fixing its backcolor, as
follows (changecolor() is a publicfuction defined for this porpose):

label1.backcolor = ChangeColour(label1.caption)
label2.backcolor = ChangeColour(label2.caption)
.............................................................
label10.backcolor = ChangeColour(label10.caption)

Is there any way, in other to reduce this code to define an array to get
something like this:
label(1 to 10)

for i=1 to 10
label(i).backcolor = ChangeColour(label(i).caption)
next i
 
R

RoyVidar

MI_ said:
I have a form with 10 labels, and a module for fixing its backcolor,
as follows (changecolor() is a publicfuction defined for this
porpose):

label1.backcolor = ChangeColour(label1.caption)
label2.backcolor = ChangeColour(label2.caption)
.............................................................
label10.backcolor = ChangeColour(label10.caption)

Is there any way, in other to reduce this code to define an array to
get something like this:
label(1 to 10)

for i=1 to 10
label(i).backcolor = ChangeColour(label(i).caption)
next i

Try something like this

for i=1 to 10
Me.Controls("label" & i).backcolor = _
ChangeColour(Me.Controls("label" & i).caption)
next i
 
G

Guest

I use the following.

Function changecolor(strfrmName As String, strlbl As String)
Forms(strfrmName).Form(strlbl).BackColor = RGB(0, 255, 0)
End Function

Then I call it in my sub

For i = 1 To 5
changecolor Screen.ActiveForm.Name, "Label" & i
Next i

Daniel
 
G

Guest

Do not forget "To use the BackColor property, the BackStyle property, if
available, must be set to Normal." (taken from the help file).

Daniel
 
T

Terry Kreft

Dim i as Integer

For i = 1 to 10
With Me.Controls("label" & i)
.BackColor = ChangeColour(.Caption)
End With
Next
 

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