Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Swapping Inner/Outer FOR Statements during run-time Possible?

Posted on 1998-11-26
2
Medium Priority
?
151 Views
Last Modified: 2010-05-03
In my program i have two "for" statements; one nested within the other. Inside the inner most "for" statment is code that makes use of both incrementing "for" statement values. What i want to be able to do is to make the inner most "for" statement become the outermost and the outermost now becomes the innermost and i want to do it during runtime. I know this is not possible but i was hoping if any of you could come up with any viable solutions that did something similiar to this. Perferably i DO NOT want to duplicate the code and put "if" statements around it (the code that the "for" statements encapsulate is HUGE). Here is an example:

for com_inc = 0 to COMLIMIT
  for tty_inc = 0 to TTYLIMIT
      Debug.print "TTY = " & tty_inc & " COM = " & com_inc
  next tty_inc
next com_inc

Output would look like this:
----------------------------
TTY = 0 COM = 0
TTY = 1 COM = 0
TTY = 2 COM = 0
TTY = 3 COM = 0
    .
    .
    .

Now the tricky part ... i want to be able to send a signal so the output will now look like this:

TTY = 0 COM = 0
TTY = 0 COM = 1
TTY = 0 COM = 2
TTY = 0 COM = 3
    .
    .
    .

Once again, i know i can just duplicate my original code and encapsulate it all with an "if" statement to choose which ever style i want BUT i would prefer something that took up less space (my code within the "for" statements is BIG) ... something more clever (or even obvious that i may have overlooked).  Thanks very mcuh
0
Comment
Question by:aniston
2 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 40 total points
ID: 1446900
I have not tried it but try the following

 com_inc = 0  
  tty_inc = 0
  do
    Debug.print "TTY = " & tty_inc & " COM = " & com_inc
    if (orderTTYCOM) then
        tty_inc = tty_inc +1
        if (tty_inc > TTYLIMIT) then
           com_inc = com_inc +1
           if (com_inc > comlimit) then exit while
       end if
   else
     com_inc  = com_inc +1
        if (com_inc > COMLIMIT) then
           tty_inc = tty_inc +1
           if (tty_inc > TTYlimit) then exit while
       end if
  end if
while true
0
 

Author Comment

by:aniston
ID: 1446901
Thanks very much!!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question