PROGRAM ‘MENU’
This set of procedures is a general version of a menu bar system that I use in some of my programs. It might be of interest to others for use in programs that require keyboard option selection.
When run the program displays a menu bar on the screen with one highlighted item. The left and right cursor keys move the item. The Enter key executes the menu choice.
The first menu is used here to set a flag for printer/screen output, to rerun or to stop the program. If the printer/screen option is selected the program moves to the first submenu which contains two procedure selections, a submenu or return to the previous menu. The submenu contains further procedures and also a return to the previous menu. Each time a procedure option is entered, the procedure is executed and the menu bar reappears upon completion of the procedure.
The best way to see how the program works is to run it and look what happens. The procedure used here is a one line text output to the screen, but it can be replaced by any other type of procedure.
THE PROGRAM
c: channel for menu bar
l: length of menu text block
menu_load: sets up the text in the
menu bars, can be modified
for other applications.
main_menu: printer flag and RUN or
STOP. The action can be
modified to suit other requi-
rements. The menu jumps to
menu_1 after flag selection.
menu_1: selects pocedures 1 or 2,
submenu 2, or returns. The
actions can be modified to suit
other requirements. Unless the
submenu is selected, the
program returns to the main
menu upon completion of the
procedures.
menu_2: selects procedures 3P, 3S, 4
or 5 or returns. Upon compl-
etion of the procedure the
program returns to the submenu.
menu (A): This procedure does the
screen printing and keeps track
of highlight position through
the variable TEMP. The command
KEYROW is used for quick
reaction to a keypress (see QL
manual.).
prc : Procedure used to demonstrate
the procedure execution. It is
not a part of the menu program.
When experimenting with this program you will find out that it can be modified in many respects to fit specific requirements. GOOD LUCK.
100 C=0:L=10:MENU_LOAD:MAIN_MENU
110 DEFine PROCedure MAIN_MENU
120 LOCal LOOP:REPeat LOOP
130 MENU 0:SELect ON TEMP
140 =0:FLAG=0:EXIT LOOP
150 =1:FLAG=1:EXIT LOOP
160 =2:CLEAR:RUN:=3:STOP
170 END SELect
180 END REPeat LOOP:MENU_1
190 END DEFine MAIN_MENU
200 DEFine PROCedure MENU_1
210 LOCal LOOP:REPeat LOOP
220 MENU 1:SELect ON TEMP
230 =0:PRC 1:=1:PRC 2
240 =2:MENU_2:=3:CLS:EXIT LOOP
250 END SELect
260 END REPeat LOOP:MAIN_MENU
270 END DEFine MENU_1
280 DEFine PROCedure MENU_2
290 LOCal LOOP:REPeat LOOP
300 MENU 2:SELect ON TEMP
310 =0:IF FLAG:PRC "3P":ELSE :PRC "3S":END IF
320 =1:PRC 4:=2:PRC 5
330 =3:CLS:EXIT LOOP
340 END SELect
350 END REPeat LOOP:MENU_1
360 END DEFine MENU_2
370 DEFine PROCedure MENU(A)
380 LOCal B,D,LOOP
390 CLS#C:INK#C,7:STRIP#C,0
400 FOR B=3 TO 0 STEP -1
410 IF B=0:INK#C,0:STRIP#C,7:END IF
420 AT#C,0,10+L*B:PRINT#C,OPT$(A,B)
430 END FOR B
440 REPeat LOOP
450 PAUSE:D=KEYROW(1)
460 IF D=1:EXIT LOOP:END IF
470 IF D=2 OR D=16
480 STRIP#C,0:INK#C,7
490 AT#C,0,10+L*B:PRINT#C,OPT$(A,B)
500 IF D=2:B=B-1:END IF
510 IF D=16:B=B+1:END IF
520 IF B<0:B=3:END IF
530 IF B>3:B=0:END IF
540 STRIP#C,7:INK#C,0
550 AT#C,0,10+L*B:PRINT#C,OPT$(A,B)
560 END IF
570 END REPeat LOOP
580 TEMP=B:PAPER#C,0:INK#C,7:CLS#C
590 END DEFine MENU
600 DEFine PROCedure MENU_LOAD
610 DIM OPT$(3,4,L-1):RESTORE 660
620 FOR A=0 TO 2
630 FOR B=0 TO 3:READ OPT$(A,B):END FOR B
640 END FOR A
650 END DEFine MENU_LOAD
660 DATA ' SCREEN ',' PRINTER ',' START ',' STOP '
670 DATA ' PROC 1 ',' PROC 2 ',' MENU 2 ',' RETURN '
680 DATA ' PROC 3 ',' PROC 4 ',' PROC 5 ',' RETURN '
690 DEFine PROCedure PRC (A$)
700 CLS:PRINT 'PROCEDURE '&A$
710 END DEFine PRC
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.