home *** CD-ROM | disk | FTP | other *** search
/ Share Gallery 1 / share_gal_1.zip / share_gal_1 / UT / UT070.ZIP / MENUS.EXE / YESNO.MNU < prev   
Text File  |  1989-11-28  |  3KB  |  102 lines

  1.  
  2. Comment
  3. ===================================================================
  4.  
  5. This is a MarxMenu that you would use in a BATCH file in order to
  6. return an ErrorLevel code. This ErrorLevel code can be used to
  7. control the execution of a BATCH file as follows:
  8.  
  9. You have a BAT file called YESNO.BAT which branches to YES.BAT or
  10. NO.BAT depending on how you answer.
  11.  
  12. MARXMENU YESNO 'Are you a programmer' N 15 1 0
  13. IF ERRORLEVEL 1 YES
  14. NO
  15.  
  16. In this example, we wait for a yes/no answer. If return is pressed
  17. or no answer is given in the alloted time, the default answer is
  18. assumed. In this example a Yes returns ErrorLevel 1 and no returns
  19. ErrorLevel 0.
  20.  
  21. If WaitTime = 0 then it will wait forever for a KeyPress
  22. The Maximum WaitTime is 99 seconds.
  23.  
  24. StandardIO is selected allowing this program to be run over a modem
  25. if necessary.
  26.  
  27. ===================================================================
  28. EndComment
  29.  
  30. Var
  31.    Answer Question DefaultAnswer OppositeAnswer QTimer WaitTime
  32.    LastSecond YesErrorLevel NoErrorLevel
  33.  
  34. Question = NextWord(CmdLine)
  35. DefaultAnswer = NextWord(CmdLine)
  36. WaitTime = Value(NextWord(CmdLine))
  37. YesErrorLevel = Value(NextWord(CmdLine))
  38. NoErrorLevel = Value(NextWord(CmdLine))
  39.  
  40. StandardIO
  41.  
  42. If NoErrorLevel = YesErrorLevel
  43.    Writeln
  44.    Writeln 'MarxMenu Programing Example:'
  45.    Writeln 'CopyRight 1989 by Marc Perkel'
  46.    Writeln
  47.    Writeln 'Usage:'
  48.    Writeln '  MARXMENU YESNO <Question> <Default> <Wait Time> <Yes Error> <No Error>'
  49.    Writeln
  50.    Writeln '  <Question>  is the yes/no question to ask.'
  51.    Writeln '  <Default>   is the answer assumed if return is pressed or timeout.'
  52.    Writeln '  <Wait Time> is the number of seconds to wait for an answer.'
  53.    Writeln '  <Yes Error> is the DOS ErrorLevel to return for a YES answer.'
  54.    Writeln '  <No Error>  is the DOS ErrorLevel to return for a NO answer.'
  55.    Writeln
  56.    Writeln 'Example:'
  57.    Writeln "  MarxMenu YesNo 'Are you a programmer' N 15 1 0"
  58.    ExitCode = 0
  59.    ExitMenu
  60. Endif
  61.  
  62. DefaultAnswer = UpperCase(DefaultAnswer)
  63. Writeln
  64. Write Question
  65. If DefaultAnswer = 'Y'
  66.    Write ' (Y/n)? '
  67.    OppositeAnswer = 'N'
  68. Else
  69.    Write ' (y/N)? '
  70.    OppositeAnswer = 'Y'
  71. Endif
  72.  
  73. Answer = DefaultAnswer
  74. WaitTime = Min(WaitTime,99)
  75.  
  76. If WaitTime > 0
  77.    LastSecond = Second
  78.    While (not KbdReady) and (LastSecond = Second)   ;First Second
  79.    EndWhile
  80.    QTimer = WaitTime
  81.    While not KbdReady and (QTimer > 0)               ;CountDown
  82.       LastSecond = Second
  83.       Write QTimer
  84.       If QTimer = 9 then Write(' ' + BkSp)
  85.       Write BkSp
  86.       if QTimer > 9 then Write BkSp
  87.       While (not KbdReady) and (LastSecond = Second)
  88.       EndWhile
  89.       if not KbdReady then QTimer = QTimer - 1
  90.    EndWhile
  91. EndIf
  92. if KbdReady or (WaitTime = 0) then Answer = UpperCase(ReadKey)
  93. if Answer <> OppositeAnswer then Answer = DefaultAnswer
  94. If Answer = 'Y'
  95.    ExitCode = YesErrorLevel
  96.    Writeln 'Yes'
  97. Else
  98.    ExitCode = NoErrorLevel
  99.    Writeln 'No'
  100. Endif
  101.  
  102.