home *** CD-ROM | disk | FTP | other *** search
- PROGRAM Choice;
-
- { PROGRAM NAME: CHOICE Ver. 1.0 Copyright (c) 1984 Bruce N. Wheelock
-
- NOTICE: A limited license is granted to all users of this program to
- make copies of this program and distribute them to other users,
- on the following conditions:
-
- 1. The program is not to be distributed to others in
- modified form.
- 2. No fee (or other consideration) is to be charged for
- copying or distributing the program without an
- express written agreement with the author.
- 3. The copyright and description information in this
- program is not to be altered or removed.
-
- AUTHOR: Bruce N. Wheelock
- 6333 College Grove Way, Apt. G-4
- San Diego, CA 92115
-
- The author may be contacted on the following public access
- computer systems:
-
- P.dBMS #1 (619) 444-7099 (address to Bruce N. Wheelock)
- FidoNet/FTL (619) 286-7838 (address to Bruce Wheelock)
-
- DESCRIPTION: This program is designed to be used within a batch file under
- PC-DOS/MS-DOS ver. 2.0 or later, to permit menu selection
- control; it will mainly be of interest to hard drive users.
- The program is called with an integer argument which
- specifies the largest choice number which may be selected.
- CHOICE will prompt the user for his choice number and check to
- see whether the number entered is an integer between 0 and the
- value in the argument. If it is not, an error message is dis-
- played and the user is again prompted for a choice. If the
- number is within the range, ERRORLEVEL (a batch-testable
- value) is set to the number entered, and the program ends.
- ERRORLEVEL may then be tested by the batch file and action
- taken based on the result.
-
- USE: Here is a sample batch file:
-
- ECHO OFF
- :START
- CLS
- ECHO 1. Run LOTUS 1-2-3
- ECHO 2. Run Microsoft WORD
- ECHO 3. Run Microsoft SPELL
- ECHO 4. Run SMARTCOM II
- ECHO 0. Exit to DOS
- ECHO
- REM The previous line has two (2) blanks after ECHO
- IF NOT ERRORLEVEL 4 GOTO THREE
- SCOM
- GOTO START
- :THREE
- IF NOT ERRORLEVEL 3 GOTO TWO
- SPELL
- GOTO START
- :TWO
- IF NOT ERRORLEVEL 2 GOTO ONE
- WORD
- GOTO START
- :ONE
- IF NOT ERRORLEVEL 1 GOTO ZERO
- LOTUS
- GOTO START
- :ZERO
- IF NOT ERRORLEVEL 0 GOTO START
- REM End of batch file
-
- NOTES: When ERRORLEVEL is checked in a batch file, the IF is satis-
- fied if the value is equal to or greater than the value
- tested. Because of this, testing must begin at the highest
- possible value and decrease to the lowest. Detailed infor-
- mation on batch files may be found in your DOS manual.
-
- Turbo PASCAL .COM programs have an instruction to clear the
- screen when the program begins. This is not desirable in this
- program. It is necessary, therefore, to disable the screen
- clearing instruction. This instruction is located at memory
- address 02FC. The instruction is CD10 (Interrupt 10). It may
- be disabled by changing the instruction to 9090. To do this
- using DEBUG.COM, follow these procedures:
-
- A>DEBUG CHOICE.COM
- -E02FC
- NNNN:02FC CD.90 [Type the 90 and press return]
- -E02FD
- NNNN:02FD 10.90 [Type the 90 and press return]
- -W
- Writing nnnn blocks
- -Q
- A>
-
- For instructions on using DEBUG, consult your DOS manual.
-
- Program results will be unpredictable if the argument to the
- program is not an integer. If no argument is specified, the
- value defaults to 1 (one).
-
- ACKNOWLEDGMENTS: The procedure GetMax is adapted from CMDLINE.PAS, posted
- on FidoNet/FTL by Bruce Webster (SYSOP). The procedure
- SetErrlevel is adapted from a program by Bruce Webster
- and myself. Help in eliminating the screen clear
- instruction was provided by Bill Parker of Ashton-Tate. }
-
-
- CONST
- Col = 15; { The column in which the prompt response occurs }
-
- TYPE
- Result = RECORD { Record of DOS registers for DOS interface }
- AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS : INTEGER;
- END; { RECORD Result }
-
- CommandString = string[127]; { Type for buffer to receive the argument }
-
- VAR
- Row : INTEGER; { Variable for the screen row of the cursor }
- Regs : Result; { DOS registers variable }
- ErrorLevel : INTEGER; { Variable to hold the error level to be set }
- Ok : BOOLEAN; { Valid entry check flag }
- CL : CommandString absolute cseg:$80; { Argument buffer }
- Max : INTEGER; { Numeric representation of the argument }
-
-
- PROCEDURE GetMax(VAR Max : INTEGER);
-
- { GetMax retrieves the argument to the program, converts it to an integer, &
- places the integer in the variable MAX. This is the value of the highest
- legal user response. If no argument is given, the default is 1 (one). }
-
- VAR
- I, Temp : INTEGER; { Local index and work variables }
-
- BEGIN
- Temp := LENGTH(CL); { Length of argument }
- FOR I := 1 TO Temp DO { Set loop to argument length }
- IF CL[I] <> ' ' THEN { Ignore imbedded/leading blanks }
- Max := (Max*10) + (ORD(CL[I]) - 48); { Convert char to number }
- IF Temp = 0 { If length is zero, no argument was given }
- THEN { so. . . }
- Max := 1; { default Max to one }
- END; { PROCEDURE GetMax }
-
-
- FUNCTION Valid(ErrorLevel:INTEGER; Max : INTEGER) : BOOLEAN;
-
- { Valid checks to see if the number entered by the user is between 0 and Max }
-
- BEGIN
- IF (ErrorLevel >= 0) AND (ErrorLevel <= Max) { Range check }
- THEN
- Valid := TRUE { If in range, set result to TRUE }
- ELSE
- Valid := FALSE; { If out of range, set result to FALSE }
- END; { FUNCTION Valid }
-
-
- PROCEDURE SetErrlevel(ErrorLevel : INTEGER);
-
- { SetErrlevel sets places 4C hex in AH and ErrorLevel in AL, then performs an
- MSDOS call with the record of registers. The MSDOS call forces an immediate
- program termination, so there is no return from this procedure. }
-
- BEGIN
- WITH Regs DO AX := $4C00 OR ErrorLevel; { Set contents of AX register }
- MSDOS(Regs); { MSDOS call function }
- END; { PROCEDURE SetErrlevel }
-
-
- PROCEDURE ErrorMsg;
-
- { ErrorMsg is called if PROCEDURE Valid returned a FALSE. It displays an
- error message, sounds a tone, and prompts for a new value. }
-
- BEGIN
- SOUND(400); { Activate speaker }
- LowVideo; { Set character display to 'dim' }
- WRITE('Not a valid choice. Must be ');
- NormVideo; { Set character display to normal }
- WRITE('1 ');
- LowVideo; { Set character display to 'dim' }
- WRITE('through ');
- NormVideo; { Set character display to normal }
- WRITE(Max);
- LowVideo; { Set character display to 'dim' }
- WRITE(' or ');
- NormVideo; { Set character display to normal }
- WRITE('0.');
- DELAY(400); { Approx. 400 millisecond delay for sound }
- NOSOUND; { Shut-off speaker }
- END; { PROCEDURE ErrorMsg }
-
-
- BEGIN { Main }
-
- {$I-} { Disable automatic run-time I/O error checking }
- Max := 0; { Init Max }
- GetMax(Max); { Get the highest legal value }
- Ok := FALSE; { Init Ok }
- WRITE('Enter choice: '); { Prompt user }
- REPEAT { UNTIL Ok }
- READLN(ErrorLevel); { Keep taking values. . . }
- IF IOResult <> 0 { handle non-integer entries. . . }
- THEN { by changing the response. . . }
- ErrorLevel := Max + 1; { to more than Max. . . }
- Ok := Valid(ErrorLevel, Max); { checking the response. . . }
- Row := WhereY - 1; { keeping track of cursor line. . . }
- IF Ok { and when value is valid. . . }
- THEN
- BEGIN
- GOTOXY(1,Row + 1); { going to error line to. . . }
- ClrEol; { erase possible error message. . . }
- WRITELN; { feed a blank line and. . . }
- SetErrlevel(ErrorLevel) { SetErrorlevel forcing program end }
- END { THEN of IF Ok }
- ELSE { but if its is not valid. . . }
- BEGIN
- ErrorMsg; { display an error message. . . }
- GOTOXY(Col,Row); { go up a line. . . }
- ClrEol { erase the illegal entry. . . }
- END; { ELSE of IF Ok } { and try again. }
- UNTIL Ok; { end of REPEAT loop }
- END. { Main }