Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Visual Basic for Applications

Post new topic   Reply to topic
Variable as part of object name
View previous topic :: View next topic  
Author Message
noke
Newbie


Joined: 30 Apr 2004
Posts: 3

PostPosted: Apr 30th, 2004 12:30 PM    Post subject: Variable as part of object name Reply with quote

I'm pretty new to VBA.

Can someone tell me how to reference an object using a variable as part of its name? For example, I'm writing a loop to assign captions to sequentially named Labels. I think the following shows what I'm trying to accomplish.

For i = 1 to 40
Label(i).Caption = "...whatever....."
Next i

Thanks
Back to top
View user's profile Send private message
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: Apr 30th, 2004 12:43 PM    Post subject: Reply with quote

Well, you hit it on the head...but, you need to rename all the labels. Set the index property of your "label1" control to 1, and rename it to "label". Do the same for each label you have. Then your code will work.

VB will automatically do this for you if you select yes when it asks you if you want to create a control array when cutting and pasting controls.
_________________
If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too.
Back to top
View user's profile Send private message
noke
Newbie


Joined: 30 Apr 2004
Posts: 3

PostPosted: Apr 30th, 2004 03:40 PM    Post subject: Reply with quote

Sorry, you'll have to excuse my ineptitude!

Which index property? There is no index property (other than Tab Index) listed in the Properties for the Label object, and if I try to rename more than one Label to "Label" I get an error message.

Confused
Back to top
View user's profile Send private message
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: Apr 30th, 2004 05:18 PM    Post subject: Reply with quote

Which application are you using it in? Access, VB, Excel?
_________________
If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too.
Back to top
View user's profile Send private message
noke
Newbie


Joined: 30 Apr 2004
Posts: 3

PostPosted: May 3rd, 2004 08:26 AM    Post subject: Reply with quote

Sorry....Excel
Back to top
View user's profile Send private message
Andir
Centurion


Joined: 21 Dec 2003
Posts: 184
Location: Chicago Area

PostPosted: May 3rd, 2004 12:52 PM    Post subject: Reply with quote

Well, I'm not too familiar with working in Excel with them, but I did find out you can set the index property at runtime. That doesn't help much unless your creating the labels on opening the document, which sucks. I'm stuck as well on this question without more research. Why are you using the label control? Can you use the cells on the sheet to label something?
_________________
If you happen to see little people sitting on your desk...don't tell anyone or they might think your crazy too.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Visual Basic for Applications All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic