View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Charles Hamlyn Charles Hamlyn is offline
external usenet poster
 
Posts: 4
Default Looping with incremental variable/object names

right now I have code similar to below:

Variable1 = Form1.TextboxWidth1 * Form1.TextboxLength1
Variable2 = Form1.TextboxWidth2 * Form1.TextboxLength2
Variable3 = Form1.TextboxWidth3 * Form1.TextboxLength3
Variable4 = Form1.TextboxWidth4 * Form1.TextboxLength4
Variable5 = Form1.TextboxWidth5 * Form1.TextboxLength5
....

It's more complicated than that, but you get the idea. So anyway, I'd like
to make a loop to accomplish the same task. Something along the lines of:

For LoopCounter = 1 to 4
NewVariableName = "Variable" & LoopCounter
NewTextWidthName = "Form1.TextBoxWidth" & LoopCounter
NewTextLengthName = "Form1.TextBoxLength" & LoopCounter

NewVariableName = NewTextWidthName * NewTextLengthName
Next LoopCounter

I'm pretty sure I've figured out how to do this in the past but I can't find
anything about it now. How can I accomplish this? Is there a better way
I'm missing?

Thank you for any assistance you can give.
Charles Hamlyn