Registrations are now open. Join us today!
There is still a lot of work to do on the wiki yet! More information about editing can be found here.
Already have an account?

Microsoft KB Archive/104047

From BetaArchive Wiki
Knowledge Base


How to Determine the Current DO Nesting Level

Article ID: 104047

Article Last Modified on 6/28/2004



APPLIES TO

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft FoxPro 2.5b
  • Microsoft FoxPro 2.5a
  • Microsoft FoxPro 2.0
  • Microsoft FoxPro 2.5b for MS-DOS
  • Microsoft FoxPro 2.5a
  • Microsoft FoxBASE+ 2.01 for Macintosh
  • Microsoft FoxBASE+ 2.01 for Macintosh



This article was previously published under Q104047

SUMMARY

FoxBASE+ and FoxPro allow DO programs to be nested. The maximum number of nesting levels for FoxBASE+ is 24, while FoxPro allows a maximum of 32 levels and Visual FoxPro allows a maximum of 128 levels. Exceeding this limit results in error number 103, "DO nesting too deep."

MORE INFORMATION

DO levels are incremented as follows:

  1. When a DO program1 command is issued in the Command window, the DO level is set to 1.
  2. If program1 includes a DO program2 statement, the DO level is incremented to 2. The DO level is incremented each time another DO program statement is executed. In this scenario, program1 would be referred to as the calling program, and program2 as the called called program.
  3. If a called program returns to a calling program, either by executing all commands in the called program, or by explicitly issuing a RETURN command, the DO level is decremented by 1.

The following procedure allows you to determine the current DO level through use of the SYS(16) function. The SYS(16) function returns the name of the currently executing program. It also allows an optional numeric argument that indicates from how many levels back the program name should be fetched.

  1. Create a program named DOLVL.PRG with the following commands:

          * Memory variable used:
          * current - name of currently executing program
          * do_ctr - counter which indicates current do level
    
          current = SYS(16)
          do_ctr = 1
          DO WHILE .T.
             IF SYS(16,do_ctr) <> current
                do_ctr = do_ctr + 1
              ELSE
                 * In FoxBASE+ or FoxPro 1.02, remove the word WINDOW
                 * in the following command
                 WAIT WINDOW "Current DO level is " + STR(do_ctr,1,0)
                 EXIT
              ENDIF
          ENDDO
  2. Save and execute the program. A message will be displayed as follows:

    Current DO level is 1

  3. Create a program named TEST.PRG with the following command and execute the program:

    DO dolvl.prg

  4. A message will be displayed as follows:

    Current DO level is 2



Additional query words: VFoxWin FoxDos FoxWin foxbase+/mac

Keywords: kbenv KB104047