Solved

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

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

772 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