Solved

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

Posted on 1998-11-26
2
139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

749 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