Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

label in for loop

label in for loop

label in for loop

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

RE: label in for loop

You already have a solution, so what is the problem?

RE: label in for loop

You can use the CallByName function to refer to objects using their name as text.

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

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.

RE: label in 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"

RE: label in for loop

I think you may will find that xwb was referring to the array solution...

RE: label in for loop

Label5 is a bad name for a label. (IMHO)
I would suggest:


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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close