home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
info
/
dostips2.arc
/
DOSMENUS.TXT
< prev
next >
Wrap
Text File
|
1985-11-24
|
11KB
|
296 lines
DOS Menu Magic
(PC Magazine Vol 4 No 6 March 19, 1985 User-to-User)
If you use DOS 2.x or higher and have ever abandoned a batch file
idea for lack of a way to direct execution based on user input, the 8-
byte GETKEY.COM utility, when invoked from within a batch file, will
return the ASCII value corresponding to a single keystroke. This value
can then be tested with the batch IF ERRORLEVEL facility. Create
GETKEY.COM using DEBUG:
A>DEBUG
-E 100 B4 00 CD 16 B4 4C CD 21
-N B:GETKEY.COM
-R CX
CX 0000
:8
-W
Writing 0008 bytes
-Q
One important thing to keep in mind is that the batch test IF
ERRORLEVEL xx will be considered true if xx is less than or equal to
the GETKEY return code. It is therefore necessary to compare the
return code to its possible values in reverse-ASCII order. Copy
BASIC.COM and BASICA.COM to your disk if you wish to test the sample
MENU.BAT file shown here:
ECHO OFF
:BEG
CLS
ECHO ----------------------
ECHO 1 - Run BASIC
ECHO 2 - Run Advanced BASIC
ECHO 3 - Return to DOS
ECHO ----------------------
:ASK
ECHO Hit 1, 2 or 3
GETKEY
IF ERRORLEVEL 52 GOTO ASK
IF ERRORLEVEL 51 GOTO K3
IF ERRORLEVEL 50 GOTO K2
IF ERRORLEVEL 49 GOTO K1
GOTO ASK
:K1
BASIC
GOTO BEG
:K2
BASICA
GOTO BEG
:K3
ECHO OK!
Editor's Note: The only thing users may want to add is a series of IF
EXISTs to better inform the user if one of the menu selections is not
on the disk, e.g., use the addition below and put it between line :K1
and BASIC to check if BASIC.COM is on the disk:
IF EXIST BASIC THEN GOTO B1
ECHO BASIC.COM IS NOT ON THIS DISK
PAUSE
GOTO :BEG
:B1
-----------------------------------------------------------------
More DOS Menu Magic
(PC Magazine Vol 4 No 15 July 23, 1985 User-to-User)
The User-to-User submission in Vol 4 No 6 (above) contained
instructions for creating GETKEY.COM, a simple program that accepts
keyboard input in a batch file. The ASCII value of a key is returned
in the ERRORLEVEL, which can be accessed by statements of the type "IF
ERRORLEVEL ## <do something>". A slight variation called GETFUN.COM
will let you use function keys as inputs for GETKEY (Figure 1).
GETFUN.COM returns the extended scan code for the function keys
(and other keys -- Figure 2) and returns 255 if a nonspecial key is
pressed. As was explained, the "IF ERRORLEVEL" condition is true if
the error level is less than or equal to the returned code. A batch
file created around GETFUN should have the following features (Figure
3):
1. There must be a label, such as :CHOICE, just before the call to
GETFUN, and another, such as :BEGIN, before any lines that display a
menu.
2. The IF ERRORLEVEL statements must be in descending numerical
order and should be a continuous sequence. If they can't be continuous,
holes must be filled with statements that transfer control back to
CHOICE (e.g., IF ERRORLEVEL 71 GOTO CHOICE).
3. Since the user may press keys other than those we expect, put a
line just before the highest ERRORLEVEL that says IF ERRORLEVEL
(highest+1) GOTO CHOICE.
4. To catch keys pressed with a lower value than expected just
after the sequence of IF ERRORLEVEL, put in a simple GOTO CHOICE.
5. Each section of code that is GONE TO should end with a GOTO
BEGIN.
The "heart" of GETFUN and GETKEY is the call to DOS function 4C,
which sets the ERRORLEVEL to the value in AL. When called with 0 in
AH, interrupt 16h returns the ASCII value of the key in AL. Certain
keys, such as function or arrow keys, have no ASCII value -- in these
cases AL gets a zero, and a special code goes in AH. GETFUN checks for
this zero. If it's found, the special code is moved from AH to AL and
the ERRORLEVEL is set to it. If the key was not special, AL is filled
with FF (decimal 255). Thus any nonspecial key will have a higher
ERRORLEVEL than any special key.
The usefulness of this procedure is immense in a big batch file
menu system on a hard disk. In this case, 40 small batch files with
names A.BAT, B.BAT, and so on were converted into one big batch file.
Since each file on the hard disk takes 4K (cluster of 8 sectors), this
was a huge saving of wasted space.
Editor's Note: The ERRORLEVEL menu trick is rapidly gaining in
popularity, as it doesn't force users to hit the Enter key to enter
their menu choices. Mr. Rubenking sent this submission along with a
menu-driven set of shareware programs he calls PIANOMAN. If you're
interested in a program that very cleverly lets you play your PC like a
piano, and comes with a slew of interesting classical pieces
(including the theme to Monty Python's Flying Circus and The Lone
Ranger) already keyed in and ready to play at the touch of a function
key, contact him at:
Mr. Neil J. Rubenking
300 Page Street
San Francisco, CA 94102
- - - - -
Figure 1: GETFUN.COM
A>debug getfun.com
File not found
-a 100
-xxxx:0100 MOV AH,00
-xxxx:0102 INT 16
-xxxx:0104 CMP AL,00
-xxxx:0106 JZ 010C
-xxxx:0108 MOV AL,FF
-xxxx:010A JMP 010E
-xxxx:010C MOV AL,AH
-xxxx:010E MOV AH,4C
-xxxx:0110 INT 21
-xxxx:0112
-rcx
0000
:0012
-w
Writing 0012 bytes
-q
- - - - -
Figure 2: Extended keyboard scan codes for GETFUN.COM
FUNCTION KEYS
F1 ...F10 unshifted 59 ...68
F1 ...F10 shift 84 ...93
F1 ...F10 Ctrl 94 ...103
F1 ...F10 Alt 104 ...113
KEYPAD KEYS
unshifted Ctrl
Home 71 119
Up 72
PgUp 73 132
Left 75 115
Right 77 116
End 79 117
Down 80
PgDn 81 118
Ins 82
Del 83
ALT + REGULAR KEY
QWERTYUIOP 16 ...25
ASDFGHJKL 30 ...38
ZXCVBNM 44 ...50
1234567890-= 120 ...131
- - - - -
Figure 3: Sample menu allows GETFUN.KEY to use function keys to select
menu choices.
ECHO OFF
CLS
:BEGIN
ECHO ------------MENU:-------------
ECHO F1 SPACE PERVADERS
ECHO F2 WORDSTAR
ECHO F3 DBASE
ECHO F4 EXIT TO DOS
ECHO PRESS A FUNCTION KEY TO CHOICE
ECHO ------------------------------
:CHOICE
GETFUN
IF ERRORLEVEL 63 GOTO CHOICE
IF ERRORLEVEL 62 GOTO EXIT
IF ERRORLEVEL 61 GOTO DBAS
IF ERRORLEVEL 60 GOTO WRD
IF ERRORLEVEL 59 GOTO SPACE
GOTO CHOICE
:SPACE
BASICA PERVADER
GOTO BEGIN
:WRD
WS
GOTO BEGIN
:DBAS
DBASE
GOTO BEGIN
:EXIT
CLS
-----------------------------------------------------------------
Automated DOS Menus
(from PC Magazine Vol 4 No 14 July 9, 1985 User-to-User)
The CHOOSE.COM program (created with CHOOSE.BAS) along with the
batch file MENU.BAT can provide you with a simple way to eliminate
repetitive typing of those DOS commands that you use most frequently.
These two programs let you assign your most often used program names,
batch files, or DOS commands to single-key menu entries. MENU.BAT
displays a menu on the screen (by typing MENU.SCR) and then invokes
CHOOSE.COM. CHOOSE.COM uses function 4C hex of interrupt 21 hex to
set the DOS ERRORLEVEL value in response to a struck key. MENU.BAT
then evaluates the user's choice via the IF ERRORLEVEL subcommand.
CHOOSE.COM can set the ERRORLEVEL to any value, 0-9. When using the
IF ERRORLEVEL command in your batch files, always check the numbers in
descending order because any value that is below or equal to the actual
ERRORLEVEL value will return a true reading.
Editor's Note: This is a spiffy way to create menus since it
saves the user the trouble of needing to hit the Enter key after each
numerical menu selection is made. To use this, you'll need the
CHOOSE.COM file (by running CHOOSE.BAS), your own MENU.SCR file, and
your own MENU.BAT file. You can adapt the ones below. When these
files are on your disk, just type MENU, or include MENU as a command
in your AUTOEXEC.BAT file.
- - - - -
CHOOSE.BAS:
100 'CHOOSE.BAS: Creates CHOOSE.COM DOS menu.
110 DEFINT A-Z:TOTAL=0
120 FOR A=1 TO 114:READ A$:B=VAL("&H"+A$):TOTAL=TOTAL+B:NEXT
130 IF TOTAL<>12866 THEN PRINT "Check your typing!":END
140 RESTORE
150 OPEN "CHOOSE.COM" FOR OUTPUT AS #1
160 FOR A=1 TO 114:READ A$:PRINT #1,CHR$(VAL("&H"+A$));:NEXT
170 CLOSE:PRINT "CHOOSE.COM created."
180 END
190 DATA B8,00,00,CD,16,80,FC,02,74,32,80,FC,03,74,32,80
200 DATA FC,04,74,32,80,FC,05,74,32,80,FC,06,74,32,00,FC
210 DATA 07,74,32,80,FC,08,74,32,80,FC,09,74,32,80,FC,0A
220 DATA 74,32,80,FC,0B,74,32,B0,00,EB,33,90,B0,01,EB,2E
230 DATA 90,B0,02,EB,29,90,B0,03,EB,24,90,B0,04,EB,1F,90
240 DATA B0,05,EB,1A,90,B0,06,EB,15,90,B0,07,EB,10,90,B0
250 DATA 08,EB,0B,90,B0,09,EB,06,90,B0,00,EB,01,90,B4,4C
260 DATA CD,21
- - - - -
MENU.BAT batch file (top) and MENU.SCR display (bottom). Adapt these to
suit your needs and make sure the 1 through 8 entries match in both:
REM MENU.BAT
echo off
cls
type menu.scr
echo *** Choose Function ***
choose
if errorlevel 8 goto end
if errorlevel 7 basica draw5/M:&HEF50
if errorlevel 6 advent me
if errorlevel 5 basica keys
if errorlevel 4 talk128
if errorlevel 3 turbo
if errorlevel 2 ws
if errorlevel 1 dbase maillst.prg
:end
cls
****** System Menu ******
1. dBase II Mailing List
2. WordStar
3. Pascal
4. Telecommunicate
5. Basic
6. Adventure Game
7. Draw Pictures
8. Exit to DOS
-----------------------------------------------------------------
MENU.BAS
(PC Magazine Vol 4 No 7 April 2, 1985 User-to-User)
If you're using DOS 2.0 or above, the AUTOMENU.BAT batch file and
the MENU.BAS program will automatically generate a menu that lets you
access your BASIC programs. AUTOMENU.BAT redirects your directory to
MENU.DIR, first piping it through the DOS SORT filter to put your files
in alphabetical order. MENU.BAS extracts data from MENU.DIR, sets up
the display, and lets you select a program by typing in its number.
Line 170 of MENU.BAS determines which extensions the program will
accept, and currently ignores all extensions other than .BAS and .REM.
To list other extensions, add them to this line. The program works
fine so long as there aren't an execssive number of BASIC files on a
particular disk. To create AUTOMENU.BAT:
COPY CON:AUTOMENU.BAT
DIR|SORT>MENU.DIR
BASICA MENU.BAS