Easy stupid VB object incrementing question...

brxndxn

Diamond Member
Apr 3, 2001
8,475
0
76
I want to run a script that is going through all the objects on a display and setting the 'caption' properties to variables.. I can easily do that by just hard-coding the text display objects..

For example.. here is my current code:

text1.Caption = "a"
text2.Caption = "a"
text3.Caption = "a"

I want to do something like this..

For varCounter 1 to 3
text+varCounter.Caption = "a"
Next

What is the syntax to use a variable in the object reference?
 

bsobel

Moderator Emeritus<br>Elite Member
Dec 9, 2001
13,346
0
0
Originally posted by: brxndxn
Originally posted by: bsobel
Create an array or a list and walk it...

Argh.. I need the syntax!!!

Depends on the version of VB your using, you really didn't provide alot of info...
 

brxndxn

Diamond Member
Apr 3, 2001
8,475
0
76
This is nuts.. I thought it would be simple to do a 'for/next' loop for something like this..

text1.caption = "a"
text2.caption = "a"
text3.caption = "a"
...
textn.caption = "a"



like..

For 1 to n
x = 1
textx.caption = "a"
x = x + 1
next

I just dunno how to get the x in my statement..
 

KLin

Lifer
Feb 29, 2000
30,951
1,080
126
Originally posted by: brxndxn
This is nuts.. I thought it would be simple to do a 'for/next' loop for something like this..

text1.caption = "a"
text2.caption = "a"
text3.caption = "a"
...
textn.caption = "a"



like..

For 1 to n
x = 1
textx.caption = "a"
x = x + 1
next

I just dunno how to get the x in my statement..

Nothing's that easy with vb. ;)
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
brxndnx, what you are trying to do i(with that logic) is not possible. You'd have to do something similar to what klin suggested above, which i'm not sure is possible in vb6.
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
for each control in me.controls
if control.name.startswith("text")
control.caption = "a"
end if
next