Solved

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

Posted on 1998-11-26
2
136 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 10 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now