home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / BATQUEST.ZIP / BATQUEST.DOC < prev    next >
Encoding:
Text File  |  1987-11-09  |  4.6 KB  |  113 lines

  1.          
  2.  
  3.  
  4.          I often find myself writing batch files for both myself and 
  5.          others, wishing that I had some sort of input capability, 
  6.          just enough to be able to branch depending on a choice made 
  7.          by the user while the batch file was running.  
  8.          
  9.          Some utilities that do this already exist, a few written for 
  10.          PC magazine, some just public domain, and even one in the 
  11.          latest version of the Norton utilities.  All of these 
  12.          utilities communicate to the batch file through the DOS 
  13.          ERRORLEVEL, which I will review below.  
  14.  
  15.          But first, an explanation.  At the time I wrote this program 
  16.          I couldn't find one that behaved the way I wanted.  The usual 
  17.          approach is just to accept a single keystroke and set the 
  18.          ERRORLEVEL variable to it's ascii value.  This requires some 
  19.          fiddling around on the part of the batch file to accommodate 
  20.          different case letters and invalid responses, not to mention 
  21.          having to keep track of the ascii value of various 
  22.          characters. Also, these utilities don't allow you to specify 
  23.          a prompt.  
  24.  
  25.  
  26.          I wanted an input utility that would:
  27.          
  28.             Let me specify a prompt 
  29.             
  30.             Let me specify what characters would be valid input, and 
  31.             not allow any other characters. 
  32.             
  33.             Would not require a carriage return to be pressed after 
  34.             typing the letter. 
  35.             
  36.             Would return an errorlevel that made sense based on the 
  37.             valid input that I specified.  
  38.  
  39.  
  40.          I think I've succeeded.  Here is the help that the program 
  41.          displays when you just type BATQUEST...
  42.          
  43.  
  44.  
  45. Format is:  BATQUEST  <prompt>  [ <choices> ]
  46.  
  47. where:   <prompt>  is a prompt string enclosed in double quote marks, and
  48.                    is required. However, you may make it null or blank.
  49.  
  50.          <choices> is an optional character string whose characters are the
  51.                    valid responses to the prompt, in increasing ERRORLEVEL
  52.                    order. Embedded blanks are not allowed.  Lowercase letters
  53.                    are translated to uppercase. <choices> must be less than
  54.                    40 characters long, and if any character is duplicated,
  55.                    only the last occurance will be found.  If <choices> is not
  56.                    present, then any character is a valid answer to the prompt.
  57.  
  58. Example.   BATQUEST "Enter your choice ==> " 123ABCQ
  59.  
  60.            will display the message:  Enter your choice ==>
  61.            which can only be answered with one of the characters:  123ABCQ
  62.            which will return an ERRORLEVEL of 4 if answered with:  A
  63.            which will return an ERRORLEVEL of 7 if answered with:  Q
  64.  
  65. written for the Public Domain by David Michmerhuizen, Oakland CA, 1986
  66.  
  67.  
  68.  
  69.  
  70.          Source code in Turbo C is included.  You may compile it with 
  71.          the small model into BATQUEST.EXE, or (as I did), compile it 
  72.          with the Tiny model, type EXE2BIN BATQUEST.EXE BATQUEST.COM, 
  73.          and delete batquest.exe. 
  74.  
  75.          BATQUEST.COM is also included for you non-hacker types, as
  76.          well as two demo batch files.
  77.  
  78.          The DOS manual (you do have one, don't you?), covers the  
  79.          ERRORLEVEL variable fairly well, but anyway, here's a quick 
  80.          refresher... 
  81.          
  82.             DOS has an internal variable named ERRORLEVEL that a 
  83.             program can set upon completion to signal normal or 
  84.             abnormal conditions.  Strangely enough, there is only one 
  85.             DOS command that uses this variable, and I've forgotten 
  86.             what it is.  This lack of recognition by the writers of 
  87.             DOS does not make it any less useful however.  You test 
  88.             the ERRORLEVEL setting in a batch file like this...
  89.             
  90.             IF ERRORLEVEL  n   command
  91.             
  92.             where n is an errorlevel number, and command is some 
  93.             command to execute.  For example...
  94.             
  95.             IF ERRORLEVEL 2 GOTO OOPS
  96.             
  97.             this statement will be TRUE (and GOTO OOPS will be 
  98.             executed), for any ERRORLEVEL that is 2 *or more*.  In 
  99.             other words, a statement such as this is actually a way of 
  100.             saying  IF ERRORLEVEL >= 2 GOTO OOOPS
  101.             
  102.              
  103.  
  104.          Written for the Public Domain  (long may it wave)  by 
  105.  
  106.          David Michmerhuizen 
  107.          Fremont  CA
  108.  
  109.          c/o Centerville BBS, (415) 793-3037
  110.  
  111.  
  112.  
  113.