Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

label in for loop

Status
Not open for further replies.

baran121

Programmer
Sep 8, 2005
337
TR
hi everyone,
i have a code which i want to move place of labels. i do like below, but it takes time in this method, is there any other way to do it easyly?
thank you

Label53.Left = Label52.Left + Label52.Width
Label54.Left = Label53.Left + Label53.Width
Label55.Left = Label54.Left + Label54.Width
Label56.Left = Label55.Left + Label55.Width
Label57.Left = Label56.Left + Label56.Width
Label58.Left = Label57.Left + Label57.Width


maybe which help me to do for loop similar below?

for x=52 to 57
Label5(x+1).Left = Label5(x).Left + Label5(x).Width
next x
 
You already have a solution, so what is the problem?
 
You can use the CallByName function to refer to objects using their name as text.
___
[pre]

For x = 52 To 57
With CallByName(Me, "Label" & x, VbGet)
CallByName(Me, "Label" & (x + 1), VbGet).Left = .Left + .Width
End With
Next x[/pre]
___

However, recommended method is to use control arrays and use the numbers in index property instead of name. This will allow you to refer to the labels using their index much more easily in the For loop.
 
You already have a solution, so what is the problem?"

The OP was looking for a faster solution "but it takes time in this method
 
I think you may will find that xwb was referring to the array solution...
 
[tt]Label5[/tt] is a bad name for a label. (IMHO)
I would suggest:
Code:
For x = 52 to 57
    lblInfo(x + 1).Left = lblInfo(x).Left + lblInfo(x).Width
Next x


---- Andy

There is a great need for a sarcasm font.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top