home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / doshelp / helpsb.zoo / help / batch / hints / subrout.hlp < prev   
Encoding:
Text File  |  1989-01-01  |  3.0 KB  |  65 lines

  1. SUBROUTINES
  2.  
  3. One BATCH file can execute another, complete with values to be substituted 
  4. for the replaceable parameters of the called BATCH file. Programs can also
  5. execute BATCH files. Environment variables can be passed as values, or 
  6. referenced directly from the DOS environment space by the called BATCH file. 
  7. A BATCH file name can even be passed as a value to the called BATCH file. 
  8. A BATCH file can call itself without getting into a loop, if it is careful 
  9. how it exits. BATCH files can be either CHAINED or NESTED.
  10.  
  11.     CHAINED    BATCH file            NESTED BATCH file
  12.  
  13. When one BATCH file chains to another    When one BATCH file executes another
  14. BATCH file to execute it, so that the    BATCH file by calling it as a sub-
  15. first BATCH file ceases processing,    routine, so that when the called BATCH
  16. and all BATCH file processing ceases    file terminates, the calling BATCH
  17. when the second BATCH file terminates.    file resumes execution just after the
  18.                     call to the subroutine.
  19.  
  20. CHAINED execution:            NESTED execution:
  21. If A executes B by:            If A executes B by:
  22.     some commands              some commands
  23.     .                      .
  24.     .                      .
  25.     .                      .
  26.     B [value1 ... [valueN]]          COMMAND /C B [value1 ... [valueN]]
  27.     .                      .
  28.     .                      .
  29.     .                      .
  30.     some more commands              some more commands
  31. then no matter what follows in         then when B terminates, A will resume
  32.     A, it will not be executed.          executing with the next command after
  33.     When B terminates, it will          the execution of B. Any changes to
  34.     return to whatever called A.      environment variables made by B will
  35.     Variables changed by B will          be lost on EXIT. A will see the 
  36.     remain changed.              values that existed when B was 
  37.                       called. In DOS 3.3 and later, CALL
  38.                       can be used instead of COMMAND /C.
  39.  
  40. Nested BATCH files terminate in one of two ways: 
  41.     explicitly by executing an EXIT command anywhere in the file.
  42.     implicitly by executing the last command in the BATCH file. 
  43.  
  44. Chained BATCH files terminate in one of two ways:
  45.     if the first link of the chain was executed directly from the keyboard,
  46.     by executing the last command in the BATCH file 
  47.     if the first link of the chain was a nested BATCH file called "X",
  48.     like a nested BATCH file (see above), and "X" will also be EXITed.
  49.  
  50. EXPLICIT EXIT:                       IMPLICIT EXIT
  51.     some commands                       some commands                  
  52.     (including skipped EXITs)        (including EXITs, skipped or not)
  53.     .                                   .
  54.     .                                   .
  55.     .                                   .
  56.     EXIT                                last command (which may be EXIT)
  57.     (the BATCH file terminates here)
  58.     .
  59.     .
  60.     .
  61.     some more commands 
  62.     (including skipped EXITs)
  63. An EXIT command which is skipped over by a GOTO or is the command on an IF 
  64. statement that evaluates as FALSE will not terminate a BATCH file.
  65.