Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Looping with incremental variable/object names

Personal E-mail from Edward R. Galimi

Charles,


You can do a for. each. next statement when working with objects.


Regards,
Eddie


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Looping with incremental variable/object names

What Galimi says is true, but not sure how that figures in here since any
loop goes through each control sequentially. I suppose you could parse the
number out of the name and do something, but for your specific example,
probably easier to do:

Assuming form1 is the name of a userform:

dim variables(1 to 5) as double

for i = 1 to 5
variable(i) = form1.Controls("TextboxWidth" & i).Value * _
form1.Controls("TextboxLength" & i).Value
Next i

If form1 is not a userform, then post back with what it is.

--
Regards,
Tom Ogilvy



"Charles Hamlyn" wrote:

Personal E-mail from Edward R. Galimi

Charles,


You can do a for. each. next statement when working with objects.


Regards,
Eddie


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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Looping with incremental variable/object names

Right, but can you do it without saying "For each textbox on Form1..."
because I need to access specific numbered objects at different times.

All I'm looking to do is build the name of an object and/or the name of a
variable into a 2nd variable. Then have VBA use the VALUE of that variable
as the object's name.

Thanks
Charles



"Charles Hamlyn" wrote in message
...
Personal E-mail from Edward R. Galimi

Charles,


You can do a for. each. next statement when working with objects.


Regards,
Eddie


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





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Incremental sheet names in a workbook Sinner Excel Worksheet Functions 2 March 30th 07 02:37 AM
Incremental Numbering: Compile Error - Variable not defined BEEJAY Excel Programming 9 September 27th 05 08:59 PM
Referencing Object Names with Variable jbl25[_8_] Excel Programming 1 August 26th 05 12:44 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
Looping to create Variable Names? Jill E Excel Programming 3 August 10th 04 12:17 AM


All times are GMT +1. The time now is 01:35 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"