Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / December 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
egerds@gmail.com - 28 Nov 2006 05:54 GMT
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.
Klatuu - 28 Nov 2006 16:26 GMT
I can't tell from your post what it is you are trying to accomplish.  I am
certain it is not as difficult as you are making it.  If you can describe the
objective, perhaps we can help find a good solution to your problem.

> 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?
[quoted text clipped - 50 lines]
> the sub to append onto the string but I have code that determines the
> number of loops.
egerds - 28 Nov 2006 22:14 GMT
> I can't tell from your post what it is you are trying to accomplish.  I am
> certain it is not as difficult as you are making it.  If you can describe the
> objective, perhaps we can help find a good solution to your problem.

I am writing code to brute force solve/recreate 2^54 Number. I have
broken this into 2 long integers as I am not sure how in VBA to store
2^54 as a single number accurately.

54 toggles on a form can be expressed as 54 bit, as one toggles it
would affect 4 other bits, this as been loaded into a two dimensional
array, this array would be XOR to the current value (stored as 2 long
integers).1,2,4,8,16,etc to calculate it down to 0.

Lights Out Cube Sovler via access 2007 form and tables.
egerds - 09 Dec 2006 07:22 GMT
> > I can't tell from your post what it is you are trying to accomplish.  I am
> > certain it is not as difficult as you are making it.  If you can describe the
> > objective, perhaps we can help find a good solution to your problem.
> >
> Lights Out Cube Sovler via access 2007 form and tables.

Example code

Private Sub Command_Solve_Click()
Dim array_toggles_form(0 To 53), array_toggles_solving(0 To 53)
Dim array_toggles_result(0 To 53), array_toggles_answer(0 To 53)
Dim bytX As Byte, bytY As Byte, bytZ As Byte, intButtonCount As Byte
Dim strToggleName As String, strSolve As String

'Fill array form and solving
For bytX = 0 To 53
 strToggleName = lstr_Toggle & bytX
 array_toggles_form(bytX) = Me(strToggleName)
 array_toggles_solving(bytX) = Me(strToggleName)
 array_toggles_result(bytX) = Me(strToggleName)
 'array_toggles_answer(bytX) = Me(strToggleName)
Next

'start testing
For intButtonCount = 1 To Me.Text_Par
 If intButtonCount > 1 Then
  'I would need to add a loop for each of intbuttoncount or have a
recursive sub call
  'this code example only works for 2 button presses
  For bytZ = 1 To 53
   strSolve = bytZ & " "
   Call ToggleArray(bytZ, array_toggles_solving)
   GoTo Loop2in
Loop1Return:
  Call SetArray(array_toggles_form, array_toggles_solving)
  Next
 End If
 'array_toggles_solving should be set here to ?

 'Call SetArray(array_toggles_form, array_toggles_solving)
 'MsgBox "outer loop" & intButtonCount
Next
'reset form
For bytX = 0 To 53
 strToggleName = lstr_Toggle & bytX: Me(strToggleName) =
array_toggles_form(bytX)
Next
'this is the code for 1 button press solve
For bytX = 0 To 53
 Call ToggleArray(bytX, array_toggles_result)
 If Check_Complete(array_toggles_result) = True Then
  strSolve = strSolve & bytX
 End If
 Call SetArray(array_toggles_solving, array_toggles_result)
Next

MsgBox "solved by pressing " & strSolve
Exit Sub ' End of solve button
Loop2in:
 For bytX = 0 To 53
  Call ToggleArray(bytX, array_toggles_result)
  If Check_Complete(array_toggles_result) = True Then
   strSolve = strSolve & bytX
   MsgBox strSolve
   Exit Sub
  End If
  Call SetArray(array_toggles_solving, array_toggles_result)
 Next
GoTo Loop1Return
End Sub
Sub ToggleArray(ByRef bytX, array_toggles_result)
Dim bytY As Byte, strToggleName As String
Me(lstr_Toggle & bytX) = Not Me(lstr_Toggle & bytX)
array_toggles_result(bytX) = Not array_toggles_result(bytX)
For bytY = 1 To 4
 strToggleName = lstr_Toggle & pAffected(bytX, bytY)
 Me(strToggleName) = Not Me(strToggleName)
 array_toggles_result(pAffected(bytX, bytY)) = Not
array_toggles_result(pAffected(bytX, bytY))
Next
End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.