Menu Program

Author(s): Wilf Rigter
Publication: ZX-Appeal
Date: March - April 1989
Pages: 8-9
   1 REM * MENUPROGRAM REV 3.0 *
2 REM * BY W.RIGTER FEB/86 *
3 REM ***DO NOT USE RUN***
4 REM USE GOTO 100 TO FORMAT
5 REM USE GOTO START TO START
6 REM
10 REM FORMAT
100 PRINT AT 21,0;"HOW MANY MENUS?"
110 INPUT ZX
120 PRINT AT 21,0;"NUMBER OF LINES PER MENU?"
130 INPUT NX
150 LET NX32=ZX*NX*32
160 LET START=9000
170 LET PRINTMENU=9100
180 LET MENUKEY=9200
185 LET LINEKEY=9250
190 LET MENU=9300
200 LET MPOS=0
210 LET MPOS1=1
220 LET M$=" ENTER MENU NUMBER (0 TO "
285 FAST
290 REM FORMAT ARRAYS
300 DIM A$(ZX,NX*32)
310 DIM A(ZX,NX)
500 FOR Z=1 TO ZX
510 FOR N=1 TO NX
550 LET A(Z,N)=8999
560 LET A$(Z,32*N-31 TO )=CHR$ (N+27)+"."
570 LET A$(Z,NX*32-28 TO NX*32)="SELECT MENU"
580 NEXT N
590 NEXT Z
600 LET A$(ZX,NX*32-92 TO NX*32-64)="SUBROUTINE ADDRESS EDITOR"
610 LET A$(ZX,NX*32-60 TO NX*32-32)="MENU TEXT EDITOR"
620 LET A$(ZX,NX*32-124 TO NX*32-96)="MENU SCREEN POSITION"
800 FOR Z=1 TO ZX
810 LET A(Z,NX)=9500
820 NEXT Z
830 LET A(ZX,NX-1)=9600
840 LET A(ZX,NX-2)=9700
850 LET A(ZX,NX-3)=9800
990 CLS
999 GOTO START
1000 REM START OF USER PROGRAM
8999 RETURN
9000 REM START
9010 LET Z=1
9020 LET N=1
9030 LET Z1=Z
9050 REM MAIN LOOP
9060 SLOW
9070 GOSUB MENU
9080 GOTO 9060
9100 REM PRINTMENU
9110 PRINT AT MPOS,6;"MENU ";CHR$ (Z+27);" - LINE ";CHR$ (N+27);
9120 PRINT AT MPOS+2,2;A$(Z, TO NX*32-1)
9130 RETURN
9200 REM MENUKEY
9220 LET Z=CODE INKEY$-27
9225 IF Z=Z1 THEN GOTO 9220
9227 LET Z1=Z
9230 IF Z<=0 OR Z>ZX THEN GOTO 9220
9240 RETURN
9250 REM LINEKEY
9260 LET N=CODE INKEY$-27
9270 IF N<=0 OR N>NX THEN GOTO 9260
9290 RETURN
9300 REM MENU
9310 GOSUB PRINTMENU
9320 GOSUB LINEKEY
9330 GOSUB PRINTMENU
9340 GOSUB A(Z,N)
9350 RETURN
MENUPROGRAM listing, lines 9500-9940, and sample menu screens
MENUPROGRAM listing, lines 9500-9940, and sample menu screens

I did some rooting around in my tape library and discovered some programs that I always wanted to submit to the VSUG newsletter but somehow slipped away. The MENU program is what is sometimes referred to as a SHELL. This means that it is meant to be wrapped around other programs to make them more friendly. The philosophy behind this program is to give a structure or framework for your program development. MENU should be loaded and run to produce a set of menus which the user can program with a selection of menu items. The number of menus and the length of menus is entered by the user. After a few moments a menu text array is formatted with item numbers and the top menu is displayed. The last item of each menu is the submenu select function and this is now used to select the last menu. For example if you formatted 10 menus of 10 items each, then select from items 0 to 9 the last item (9). The prompt asks the user to enter a menu number and the last of these is menu 9 which the user enters. Now a new menu (9) pops into view which has been programmed with some usefull utilities. The first of these allows the user to reposition the menu at some new screen location to accomodate other user programmed displays. Just select the item by number and the prompt handles the rest. The next item is the MENU TEXT editor which is used to compose the text for each menu. First select the item and then select the menu you which to modify. At the prompt enter text for each line of the menu and terminate text with a N/L. To skip a line simply type N/L and to erase a line enter a space followed by N/L. The menus should be logically ordered to combine similar functions in each menu. (for example the utilities menu). Now return to the next item in the last menu which is the SUBROUTINE ADDRESS editor. This function is selected to assign a line number to each menu item to which the program jumps when that particular item in a menu is selected. The subroutine at that line number is written in the conventional manner and ends with a RETURN to the menu program. As an example look at the MENU program listing which is annotated to make it easier to understand. Well that is all for now and HAPPY MULTIPLE CHOICE PROGRAMMING. LOGOFF WILF R.

Sample MENU screens: menus 9, 8, 3 and 0
Sample MENU screens: menus 9, 8, 3 and 0

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.