SUB RoyalMenu (M$(), MenNum%, RoyalRow%, RoyalCol%, SpotLetrs$, SpotColr%, FKeys$, FGColr%, BGColr%, HiLiteFG%, HiLiteBG%, MaxMenuItems%, Selection%, MenuLine%, ExitCode%) ' +---------------------------------------------------------------------+ ' | SUB RoyalMenu | ' +---------------------------------------------------------------------+ ' | Not counting REM (') lines, SUB RoyalMenu has 134 lines. | ' +---------------------------------------------------------------------+ ' | RoyalMenu menu is a regular vertical menu and is able to draw | ' | horizontal lines which the block cursor will jump up or down. | ' | RoyalMenu will hi-light designated letters of a menu item. | ' +---------------------------------------------------------------------+ ' | SUB RoyalMenu is a Public Domain FreeWare program by Don Smith. | ' | There is no need to name Don as the author. | ' | EMail: smithdonb@earthlink.net Today's Date: 10/01/2002 | ' +---------------------------------------------------------------------+ ' +--------------+------------------------------------------------------+ ' | M$() | If there is only one menu, then set up the menu | ' | | items as M$(1), etc., and if there are 10 menu | ' | | items, then REDIM M$(10) in the main module. | ' | | | ' | | As there are nine different menus here running | ' | | under MagicMenu.Bas then each menu item will need | ' | | a double array. Example: M$(2, 3). The "2" is | ' | | the menu number, and the "3" is the item selected. | ' | | If there are 9 menus, and up to 15 menu items, | ' | | then REDIM M$(9, 15) in the main module. | ' | | | ' | | To force the menu to skip a line and also to | ' | | print a line, use M$(2, 3) = "-" . | ' | | | ' | | Remember that the skipped line ("-") also counts | ' | | as a menu item number. | ' | | | ' | | Example: M$(1, 1) = "Word Processing" | ' | | M$(1, 2) = "Spread Sheet" | ' | | M$(1, 3) = "-" (<-draw line here) | ' | | M$(1, 4) = "Private Letters" | ' | | | ' | | In the above example, "Private Letters" is | ' | | menu 1 and item 4, NOT item 3. | ' +--------------+------------------------------------------------------+ ' | RoyalRow% | Row to place menu. Set Row% = 1 in main program | ' | | to begin at the first item. | ' +--------------+------------------------------------------------------+ ' | RoyalCol% | The column to place menu. | ' +--------------+------------------------------------------------------+ ' | SpotLetrs$ | A string that stipulates which letters/numbers in | ' | | a menu item to hi-light with the SpotColr% color. | ' | | | ' | | Example: SpotLetrs$ = "BrT-++US-x" | ' | | ---------------------------------- | ' | | Please use both upper and lower case | ' | | letters to imulate particular letters | ' | | of a menu item. Numbers may also be used. | ' | | | ' | | A dash (-) indicates a line to skip. | ' | | A plus (+) indicates to NOT hi-light | ' | | a letter of a menu item. When a | ' | | designated hi-lite letter is pressed, the | ' | | block cursor will jump to the appropriate | ' | | row and hi-light the menu item. | ' +--------------+------------------------------------------------------+ ' | SpotColr% | The foreground color (0-15) with which to hi-light | ' | | a menu letter or number which has been set by | ' | | SpotLetrs$. | ' +--------------+------------------------------------------------------+ ' | FKeys$ | Indicates which keys to "turn on". | ' | | | ' | | Example: FKeys$ = "150" This set up will "turn | ' | | on" . The "0" of "150" | ' | | means . RoyalMenu will self-set | ' | | the key ExitCode% numbers to reflect | ' | | = 1 through = 10. | ' +--------------+------------------------------------------------------+ ' | FGColr% | The foreground menu color. | ' +--------------+------------------------------------------------------+ ' | BGColr% | The background menu color. | ' +--------------+------------------------------------------------------+ ' | HiLiteFG% | The foreground hi-light color. | ' +--------------+------------------------------------------------------+ ' | HiLiteBG% | The background hi-light color. | ' +--------------+------------------------------------------------------+ ' | MaxMenuItems%| The number of menu items. | ' +--------------+------------------------------------------------------+ ' | Selection% | The Selection is always given as a number. | ' | | IMPORTANT. PLEASE READ -> Every menu item is counted| ' | | as a number, including horizontal lines, so take | ' | | that into consideration when trapping once the | ' | | SUB exits. All selections are counted as a number, | ' | | even letters. Letter E for example would be | ' | | Selection% = 5. If there were a horizontal line | ' | | above E, then Selection% = 6. | ' +--------------+------------------------------------------------------+ ' | MenuLine% | If MenuLine% = 0 then a line in menu is ÃÄÄÄÄÄ´ | ' | | If MenuLine% = 1 then a line in menu is ÄÄÄÄÄÄÄ | ' +--------------+------------------------------------------------------+ ' | ExitCode% | ExitCode% is the last key pressed. is | ' | | ExitCode% = 27 and is ExitCode% = 13. | ' | | If an key is pressed, then the SUB will | ' | | self-set the key ExitCode% numbers to | ' | | = 1 to = 10. | ' | | | ' | | The RoyalMenu code determines that if k% = 19712, | ' | | then has been pressed. At that | ' | | point it proclaims that ExitCode% equals 11 and | ' | | exits (EXIT SUB). | ' | | | ' | | ExitCode% = 11 for | ' | | ExitCode% = 12 for | ' | | | ' | | Where did this k% number (19712) come from? Read | ' | | about CVI NUMBERS just below. | ' | | | ' +--------------+------------------------------------------------------+ ' | CVI NUMBERS | ' +---------------------------------------------------------------------+ ' | In this program, when a key is pressed, the CVI number of that | ' | key is trapped, and action is taken. The variable k% is used | ' | here, but it can be renamed, to something else, like Hit% or | ' | KeyPressed%, etc. If the key pressed is an ASCII key, then CVI | ' | will report the ASCII number. If the key pressed is an extended | ' | key, like , the number will be a unique CVI number. | ' | This SUB will respond if , , , | ' | or is pressed. The or | ' | must have been so stipulated in SpotLetrs$, or it will | ' | be ignored. The k% number, Selection% or ExitCode% number may | ' | be used upon exiting the SUB. | ' | | ' | +---------------------------------+ | ' | | CVI Number | | ' | +----------------+----------------+ | ' | | Key Pressed: | ASCII Number: | | ' | +----------------+----------------+ | ' | | .........|....27 | | ' | | .......|....13 | | ' | | Numbers 0-9...|....48 - 57 | | ' | | Letters A-Z...|....65 - 90 | | ' | | Letters a-z...|....97 - 122 | | ' | +----------------+----------------+ | ' | | ' | To find other values for k%, like , refer to the short | ' | KeyCode.Bas program below. This program allows a QuickBASIC | ' | programmer the ability to trap every key on the keyboard. The | ' | basic ingredient is the CVI command. To use this command, make | ' | 2 DO/LOOPs and a series of IFs, ELSEIFs and END IFs. | ' | | ' | Example -> | ' | ---------- | ' | DO | ' | DO | ' | Hit$ = INKEY$ | ' | LOOP UNTIL LEN(Hit$) > 0 | ' | k% = CVI(Hit$ + CHR$(0)) '<- CVI made here! | ' | IF k% = 27 THEN ' pressed | ' | END | ' | ELSEIF k% = 13 THEN ' pressed | ' | GOSUB date.info | ' | ELSEIF k% = 15104 THEN ' pressed | ' | GOSUB F1.Info | ' | END IF | ' | LOOP | ' +---------------------------------------------------------------------+ ' +---------------------------------------------------------------------+ ' | KEYCODE.BAS | ' +---------------------------------------------------------------------+ ' | Use KeyCode.Bas below to find out what the CVI numbers will be | ' | for keys you wish to trap. | ' +---------------------------------------------------------------------+ ' | ' KeyCode.Bas - By Don Smith. FreeWare and Public Domain Program. | ' | ' Date: 09/01/2002. | ' | ' +-------------------------------------------------------------+ | ' | ' | Note: To reach the extended ASCII characters 127 to 255, | | ' | ' | press down on the key, and while pressed down, | | ' | ' | type in the number on your keypad, not the numbers | | ' | ' | above then keys. | | ' | ' +-------------------------------------------------------------+ | ' +---------------------------------------------------------------------+ ' | | ' | COLOR 14, 1: CLS | ' | Top1$ = "Press a key and the KeyCode% value will be displayed." | ' | Top2$ = "-----------------------------------------------------" | ' | Top3$ = "(Press To Quit" | ' | COLOR 15, 1 | ' | LOCATE 2, 15: PRINT Top1$ | ' | LOCATE 3, 15: PRINT Top2$ | ' | COLOR 11, 1 | ' | LOCATE 4, 30, 0: PRINT Top3$ | ' | PRINT : PRINT | ' | COLOR 14, 1 | ' | DO | ' | DO | ' | Hit$ = INKEY$ | ' | IF Hit$ = CHR$(27) THEN | ' | PRINT | ' | LOCATE , 10: COLOR 15, 1: PRINT STRING$(62, "-"); | ' | PRINT | ' | LOCATE , 34: COLOR 11, 1: PRINT "Program Ends"; | ' | PRINT : PRINT | ' | END | ' | END IF | ' | LOOP UNTIL Hit$ <> "" | ' | Hit% = CVI(Hit$ + CHR$(0)) | ' | Key$ = STR$(Hit%) | ' | IF Hit% < 256 THEN | ' | LOCATE , 32, 0 | ' | PRINT Hit$ + SPACE$(9) + "= " + Key$ | ' | ELSEIF Hit% > 255 THEN | ' | LOCATE , 21, 0 | ' | PRINT "Extended Key" + SPACE$(9) + "= " + Key$; "" | ' | END IF | ' | LOOP | ' | | ' +---------------------------------------------------------------------+ LetrOrNum% = 0 SpotLetrs$ = UCASE$(SpotLetrs$) IF Selection% = 0 THEN Selection% = 1 FindRow% = RoyalRow% MaxLen% = 0 IF Selection% = 0 OR Selection% > MaxMenuItems% THEN Selection% = 1 END IF 'find length of longest M$ - next 7 lines FOR AFrame% = 1 TO MaxMenuItems% Battle% = LEN(M$(MenNum%, AFrame%)) IF Battle% > MaxLen% THEN MaxLen% = Battle% END IF NEXT MaxLen% = MaxLen% + 2 IF MenuLine% = 1 THEN FrontLine$ = CHR$(196): BackLine$ = CHR$(196) ELSE FrontLine$ = CHR$(195): BackLine$ = CHR$(180) END IF FOR Ace% = 1 TO MaxMenuItems% COLOR FGColr%, BGColr% Fox% = RoyalRow% + Ace% - 1 LOCATE Fox%, RoyalCol%, 0 IF M$(MenNum%, Ace%) = "-" THEN LOCATE Fox%, RoyalCol% - 1, 0 PRINT FrontLine$ + STRING$(MaxLen%, 196) + BackLine$ ELSE PRINT " "; M$(MenNum%, Ace%); TAB(RoyalCol% + MaxLen%); IF LEN(SpotLetrs$) > 0 THEN Apple$ = MID$(SpotLetrs$, Ace%, 1) Box% = INSTR(UCASE$(M$(MenNum%, Ace%)), Apple$) IF Box% = 0 THEN Box% = 1 IF Box% THEN COLOR SpotColr%, BGColr% LOCATE Fox%, RoyalCol% + Box%, 0 IF Apple$ <> "+" THEN PRINT MID$(M$(MenNum%, Ace%), Box%, 1); END IF END IF END IF END IF NEXT DO GOSUB paint.hilite DO k$ = INKEY$ LOOP UNTIL LEN(k$) > 0 k% = CVI(k$ + CHR$(0)) IF k% = 13 THEN ExitCode% = 13 EXIT SUB ELSEIF k% = 27 THEN 'Press and exit ExitCode% = 27 EXIT SUB 'K% = 27 K% = 122 is last letter, or "z". ELSEIF k% > 27 AND k% < 123 THEN IF k$ <> "-" THEN LetrOrNum% = INSTR(SpotLetrs$, UCASE$(k$)) IF LetrOrNum% <> 0 THEN GOSUB paint.regular.color Selection% = LetrOrNum% ExitCode% = k% GOSUB paint.hilite EXIT SUB END IF END IF ELSEIF k% = 20480 THEN ' GOSUB up.or.down ELSEIF k% = 18432 THEN ' GOSUB up.or.down ELSEIF k% > 15103 AND k% < 17409 THEN 'F1 - F10 IdentKey$ = STR$(((k% - 15104) \ 256) + 1) IdentKey$ = LTRIM$(RTRIM$(IdentKey$)) IF IdentKey$ = "10" THEN IdentKey$ = "0" END IF IF INSTR(FKeys$, IdentKey$) > 0 THEN IF IdentKey$ = "0" THEN ExitCode% = 10 EXIT SUB ELSE ExitCode% = VAL(IdentKey$) EXIT SUB END IF END IF ELSEIF k% = 19712 THEN ' ExitCode% = 11 EXIT SUB ELSEIF k% = 19200 THEN ' ExitCode% = 12 EXIT SUB END IF IF k% > 0 AND k% <> 45 AND k% <> 43 THEN letter% = INSTR(SpotLetrs$, UCASE$(k$)) END IF LOOP UNTIL letter% up.or.down: GOSUB paint.regular.color IF k% = 18432 THEN ' Selection% = Selection% - 1 IF Selection% = 0 THEN Selection% = MaxMenuItems% IF M$(MenNum%, Selection%) = "-" THEN Selection% = Selection% - 1 END IF ELSEIF k% = 20480 THEN ' Selection% = Selection% + 1 IF Selection% > MaxMenuItems% THEN Selection% = 1 IF M$(MenNum%, Selection%) = "-" THEN Selection% = Selection% + 1 END IF ELSE Selection% = LetrOrNum% END IF RETURN paint.hilite: COLOR HiLiteFG%, HiLiteBG% SpotColrBG% = HiLiteBG% GOSUB display.menu.items RETURN paint.regular.color: COLOR FGColr%, BGColr% SpotColrBG% = BGColr% GOSUB display.menu.items RETURN display.menu.items: LOCATE RoyalRow% + Selection% - 1, RoyalCol%, 0 PRINT " " + M$(MenNum%, Selection%) + STRING$(MaxLen% - LEN(M$(MenNum%, Selection%)) - 1, " ") IF LEN(SpotLetrs$) > 0 THEN AtBat$ = MID$(SpotLetrs$, Selection%, 1) Bear% = INSTR(UCASE$(M$(MenNum%, Selection%)), AtBat$) IF Bear% = 0 THEN Bear% = 1 IF Bear% THEN COLOR SpotColr%, SpotColrBG% LOCATE RoyalRow% + Selection% - 1, RoyalCol% + Bear%, 0 IF AtBat$ <> "+" THEN PRINT MID$(M$(MenNum%, Selection%), Bear%, 1); END IF END IF END IF RETURN END SUB