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

  1. This topic contains miscellaneous hints for making BATCH files execute faster.
  2.  
  3. Displaying information on the screen
  4. ------------------------------------
  5.  
  6. To display information on the screen, TYPE a previously created file rather 
  7. than using a long series of ECHO commands. You can also COPY the file to the
  8. device name CON.
  9.  
  10. Exiting from a long BATCH file
  11. ------------------------------
  12.  
  13. To immediately exit from a NESTED or CHAINED BATCH file (see the SUBROUTINES
  14. topic for information on these terms), just execute an EXIT command. It is not 
  15. necessary to GOTO the last statement of the BATCH file. However, since a BATCH 
  16. file executed directly from the keyboard ignores EXIT commands and continues
  17. until the last command is executed, there are two ways to speed up termination.
  18.  
  19.     Terminate by GOTO        Terminate by CHAINing
  20.  
  21. Insert a GOTO command at the point in     Before using the BATCH file, create
  22. the BATCH file where the decision to     an empty BATCH file, and chain to 
  23. terminate is made, referencing a label  that file at the point in the BATCH
  24. which is defined on the last line of     file where the decision to terminate
  25. the BATCH file.    The remaining lines in    is made. This is faster than the GOTO
  26. the BATCH file will be still be read,    method for long BATCH files, but 
  27. but not executed.            requires advance planning.
  28.  
  29.     some commands            To create an empty BATCH file:
  30.     GOTO EEXXIITT            
  31.     .                    REM > \EEXXIITT.BAT
  32.     .
  33.     .                    To chain to the empty BATCH file:
  34.     some more commands
  35.     .                    some commands     
  36.     .                    \EEXXIITT
  37.     .                    .
  38.     :EEXXIITT                .
  39.                     .
  40.                     .                 
  41.                     some more commands
  42.  
  43. Testing for the presence of replaceable parameters
  44. --------------------------------------------------
  45.  
  46. In a BATCH file with multiple replaceable parameters, if %N is present, then
  47. all preceding parameters (%0, %1, ... %N-1) are guaranteed to be present. It
  48. is not necessary to test for the presence of each one, just the last one.
  49. Also, to test for the presence of replaceable parameter %N, use a test of the
  50. form "IF X==X%N command" where X is a short string. This IF will only test
  51. TRUE if %N is not present.
  52.  
  53. Testing a long list of values
  54. -----------------------------
  55.  
  56. Rather than a long series of IF commands, each testing for a value, use a
  57. FOR command. For example, the series of IF commands
  58.     IF %2==YES GOTO goodvalu
  59.     IF %2==Yes GOTO goodvalu
  60.     IF %2==yes GOTO goodvalu
  61.     IF %2==ok  GOTO goodvalu
  62.     IF %2==OK  GOTO goodvalu
  63.     IF %2==Ok  GOTO goodvalu
  64.     IF %2==Y   GOTO goodvalu
  65.     IF %2==y   GOTO goodvalu
  66. could be replaced by one FOR command
  67.     FOR %%a IN (YES Yes yes ok OK Ok Y y) DO IF %2==%%a GOTO goodvalu
  68.  
  69. Condition code testing
  70. ----------------------
  71.  
  72. In a BATCH file that tests the ERRORLEVEL set by the BACKUP, RESTORE, REPLACE,
  73. or other commands that set ERRORLEVEL, use a FOR command rather than a series 
  74. of IF commands.
  75.     IF ERRORLEVEL 5 GOTO error5
  76.     IF ERRORLEVEL 3 GOTO error3
  77.     IF ERRORLEVEL 1 GOTO error1
  78.     REM if ERRORLEVEL is 0, the BATCH file will reach here...
  79.     GOTO continue
  80.     :error5
  81.     .
  82.     .
  83.     .
  84.     :continue
  85. could be replaced by one FOR command
  86.     FOR %%E IN (5 3 1) DO IF ERRORLEVEL %%E GOTO error%%E
  87.     REM if ERRORLEVEL is 0, the BATCH file will reach here...
  88.     GOTO continue
  89.     :error5
  90.     .
  91.     .
  92.     .
  93.     :continue
  94.