How to set up an undetermined number of outer for next loops

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



How do you write code to set up an undetermined number out outer loops
or to properly write a sub to call itself and exit properly?

With known values stored in arrays I am able to manually code the
number for next loops to fill a string that is passed to a sub to xor
properly.

I know how to set up an unknown SQL string but not sure how to code
undetermined number of outer loops.

This would be to create a string with number values

'Example if code has determined number of loops to be 2
Dim bytX1 as Byte, bytX2 as Byte, strToPass as string
For bytX2 = 1 to 54
For bytX1 = bytX2 to 54
'Assign string and call sub code would be here
'Code would be like
strToPass = bytX1 & "," & bytX2
call subwithabovestring(strToPass)
Next bytX1
Next bytX2

'Example if code has determined number of loops to be 7
Dim bytX1 as Byte, bytX2 as Byte, bytX3 as Byte, bytX4 as Byte
Dim bytX5 as Byte bytX6 as Byte, bytX7 as Byte, strToPass as string
For bytX7 = 1 to 54
For bytX6 = bytX7 to 54
For bytX5 = bytX6 to 54
For bytX4 = bytX5 to 54
For bytX3 = bytX4 to 54
For bytX2 = bytX3 to 54
For bytX1 = bytX2 to 54
'Assign string and call sub code would be here
'Code would be like
strToPass = bytX1 & "," & bytX2 & "," & bytX3 & "," & _
bytX4 & "," & bytX5 & "," & bytX6 & "," & bytX7
call subtoEvalTheString(strToPass)
Next bytX1
Next bytX2
Next bytX3
Next bytX4
Next bytX5
Next bytX6
Next bytX7

I have coded the inner loops to not include previous number to reduce
redundant calculations that are passed to the sub

I was thinking of using a do ... loop until but that wouldn't help
setting up the string to pass to the sub.
I have also thought of using goto and return, or recursively calling
the sub to append onto the string but I have code that determines the
number of loops.

.



Relevant Pages

  • RE: How to set up an undetermined number of outer for next loops
    ... number for next loops to fill a string that is passed to a sub to xor ... I know how to set up an unknown SQL string but not sure how to code ... undetermined number of outer loops. ... Dim bytX1 as Byte, bytX2 as Byte, strToPass as string ...
    (microsoft.public.access.modulesdaovba)
  • RE: VBA output to text editor
    ... just running empty loops took 2-3 ... RecA As String * 2 ... Sub BuildFile() ... Dim e As Integer, f As Integer, i As Long ...
    (microsoft.public.excel.programming)
  • Re: looping through IP address range
    ... For-next loops are the easiest but the the trick is to correctly fudge the ... Sub LoopAddressRange(ByVal start As String, ... Dim a2 As String = "1.2.4.255" ...
    (microsoft.public.dotnet.languages.vb)
  • Re: recalculating RAND() inside a VBA loop
    ... Calling the function from another function or sub wouldn't be a problem. ... It'll be a problem when the function originates in a cell on a worksheet. ... Dim loops As Integer ...
    (microsoft.public.excel.programming)
  • Re: code to hide rows based on criteria - but without looping
    ... "Don Guillett" wrote: ... Sub deleteblankrows() ... For Each cell In Range ... What I've read elsewhere is to avoid Loops whenever possible. ...
    (microsoft.public.excel.programming)