Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

758 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

19 Experts available now in Live!

Get 1:1 Help Now