Nesting For .. Next loops
Nesting For .. Next loops
(OP)
Say I had a number of different object and each of these objects could take a different value, how can I create a list of all possible combinations?
I think maybe an example is needed here, say I have one object called A that can take a value between 1 and 3 and object B which can be either 1 or 2, the possible combinations are
1,1
1,2
2,1
2,2
3,1
3,2
I can use nested For .. next loops for this example such as
For A = 1 to 3
For B = 1 to 2
Result = A & B
Next
Next
But the number of objects may be anything from 1 to 12 depending on the user input.
How can I change the number of nested loops depending on the user input?
I think maybe an example is needed here, say I have one object called A that can take a value between 1 and 3 and object B which can be either 1 or 2, the possible combinations are
1,1
1,2
2,1
2,2
3,1
3,2
I can use nested For .. next loops for this example such as
For A = 1 to 3
For B = 1 to 2
Result = A & B
Next
Next
But the number of objects may be anything from 1 to 12 depending on the user input.
How can I change the number of nested loops depending on the user input?





RE: Nesting For .. Next loops
resulta=inputbox( . . .)
resultb=inputbox( . . .)
for a=1 to resulta
for b=1 to resultb
hope this helps.
good luck!
-pmover
RE: Nesting For .. Next loops
Example as well as objects A and B I may also have objects C and D (and beyond), so what i need to do
For A = 1 to resulta
For B = 1 to resultb
For C = 1 to resultc
For D = 1 to resultd
Thanks
RE: Nesting For .. Next loops
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Nesting For .. Next loops
Not familiar at all!! can you offer any suggestions
Thanks
RE: Nesting For .. Next loops
you could use a recursive subroutine as well, but they're trickier to get right.
RE: Nesting For .. Next loops
CODE
Dim RetVal As String
RetVal = ""
For Idx = LoopStart To LoopEnd
If <some conditional> Then
RetVal = RetVal & DoLoop(StartValue, EndValue)
Else
RetVal = RetVal & <local expression>
End If
Next Ix
DoALoop = RetVal
End Function
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
RE: Nesting For .. Next loops