Dynamically Generating Variable Names

I have a number of objects, say shapes, which I have named s1, s2 , s3, s4 , s5.I would like to refer to the shapes fillcolor property witha routine such as FillColor(i,Color).I would like to create the following instruction:


I am unable to create the object name in this way.Can it be done? If so, how?

Unfortunately, you can’t generate variable names to use in your code. However, if you use a control array, you can programmatically do what you want to. To make a control array, give all five of the controls the same name, and set each of their Index properties to a number in a sequence (1, 2, 3, 4, 5). Then, your code can look something like this:

For i = 1 to 5   Shape(i).FillColor = ColorNext i

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: