Robert J. Beck
Two programs in Applesoft to lend variety to your program menus.
An often-ignored but essential component of many programs is the menu, or list of options. Here are a couple of variations that may make your programs a bit more interesting. Each of these imaginary menus consists of four choices: "First," "Second," "Third," and "Quit." The first three choices return you to the menu after printing a word; the "Quit" option stops the program.
An Alphabet Menu
10 R$ = "FSTQ" 20 PRINT "FIRST, SECOND, THIRD, OR QUIT" 30 PRINT "F, S, T, OR Q?"; 40 GET Z$ : PRINT 50 FOR I = 1 TO 4 60 IF Z$ = MID$ (R$, I, 1) <> THEN ON I GOTO 500, 600, 700, 800 70 NEXT I 80 PRINT "PLEASE CHOOSE"; 90 GOTO 30 500 PRINT "FIRST" : GOTO 30 600 PRINT "SECOND" : GOTO 30 700 PRINT "THIRD" : GOTO 30 800 PRINT "QUIT" : END
In the example above, you make a choice by typing a letter. The letter is an abbreviation of the choice. Abbreviations don't use much space; you can use a one or two-line menu, thus preserving previous screen output.
Line 10 sets up a string variable that is a concatenation of the abbreviations. Matching the input from line 40 with this string generates an index value that is used in the ON GOTO of line 60. Essentially, R$ is used as a table, and lines 50-70 perform a table lookup. An array, such as R$(1) - R$(4), could substitute for R$, but that's a waste of memory. Note that, especially with long option lists, this method is superior to using a series of IF/THEN statements to make the branch.
You type nothing in when using the arrow menu. Instead, you move an arrow until it points at the desired choice, then you press the RETURN key. The only way that you can accidentally make an unwanted choice is by being too hasty with the RETURN key.
Let's take it one line at a time. Line 10 initializes some important variables: HT (horizontal tab) is the number of spaces that the option list is tabbed over, VT (vertical tab) is the vertical line number at which the list begins, N is the number of options, and T is used to keep track of which choice the arrow points at. Line 20 prints the title, line 30 tabs to the preset vertical line, and lines 40-80 print the menu. The first POKE in line 90 sets line width to three spaces; the second POKE sets the left margin five spaces to the left of the menu. A VTAB to the top of the menu list completes the preparations for printing the arrow and GETting a keypress at line 110.
An Arrow Menu
10 HT = 10 : VT = 7 : N = 4 : T = VT 20 HOME : PRINT : "TEST MENU" 30 VTAB VT 40 FOR I = 1 TO N 50 READ CHOICES : HTAB HT : PRINT CHOICES : PRINT 60 NEXT 70 DATA FIRST, SECOND, THIRD, QUIT 80 VTAB22 : PRINT "TYPE ‘D’ TO MOVE DOWN, ‘U" TO MOVE UP." 90 PRINT "HIT RETURN TO SELECT." 100 POKE 33, 3 : POKE 32, HT - 5 : VTAB VT 110 HTAB 1 : PRINT "->" : GET C$ 120 If C$ = "D" AND T < N + VT - 1 THEN HTAB 1 : PRINT" " : PRINT : T = T + 1 : GOTO 110 130 IF C$ = "U" AND T > VT then HTAB 1 : CALL - 868 : VTAB PEEK (37) - 1 : T = T - 1 : GOTO 110 140 IF C$ = CHR$ (13) THEN TEXT : ON T - VT + 1 GOTO 500, 600, 700, 800 150 GOTO 110 500 HOME : SPEED = 50 : PRINT "FIRST" : SPEED = 255 : GOTO 10 600 HOME : SPEED = 50 : PRINT "SECOND" : SPEED = 255 : GOTO 10 700 HOME : SPEED = 50 : PRINT "THIRD" : SPEED = 255 : GOTO 10 800 HOME : PRINT "QUIT" : END
If T equals N + VT - 1, the arrow is at the bottom of the list; if T equals VT, then the arrow is at the top. Lines 120 and 130 illustrate two slightly different ways of moving the arrow. Line 120 prints blank spaces over it, while line 130 uses a monitor subroutine to erase it from the screen. Note that, though the cursor is moved two lines upward, the VTAB in line 130 is for PEEK (37) - 1. This is because VTAB numbers the screen lines from 1 to 24, but PEEK (37) uses 0 to 23. Unless your program uses the same line width and margin as the menu, you'll need the TEXT in line 140 to reset the text window.