SUB MesaMenu (M$(), Start%, Count%, RegColrFG%, RegColrBG%, HiLiteFG%, HiLiteBG%, MaxScrRows%, MaxScrCols%, ColumnPointer%, TweenSpace%, TableULRow%, TableULCol%, CurrentRow%, CurrentCol%, ItemNum%, ItemWidth%, FKey$, ExitCode%) ' +--------------------------------------------------------------------+ ' | MesaMenu was created by Don Smith on 08/01/2002. MesaMenu is | ' | declared Public Domain FreeWare. | ' | - - - - - - - - - - - - - - - - - - - - - - - - | ' | The MesaMenu SUB seems long, but with all the REM lines removed, | ' | it is just 254 lines in length. | ' | - - - - - - - - - - - - - - - - - - - - - - - - | ' | The MesaMenu name is abbreviated as MM to make it easier to | ' | enter at the command prompt. | ' | - - - - - - - - - - - - - - - - - - - - - - - - | ' | The object of MesaMenu is to display on screen a table menu | ' | of selected items. These may be files on the current directory, | ' | or other menu choices. Enter as a parameter a group of files | ' | which have a common extension. Example: "MM *.txt"(without quotes)| ' | For this example, MM.EXE will bring up in a viewing window all | ' | files on the current directory having the extension of .TXT. Find | ' | the word "Exten$" 14 lines from the top of the main program | ' | To view ALL the files on the current directory, use "MM *.*" | ' | To change to your QuickBASIC files, use "MM *.bas" To view files | ' | with NO extension, use "MM *." . If the DOS command, "DIR *." | ' | is used at the prompt, it will display all directories and files | ' | having no extensions. | ' | - - - - - - - - - - - - - - - - - - - - - - - - | ' | The program user may move the block cursor by pressing: | ' | . In | ' | addition, the user may press a letter, a number, an exclamation | ' | , or an underline <_>. The hi-lite cursor | ' | will jump to the first item beginning with the letter pressed, | ' | and, if there are any more items beginning with that letter, it | ' | will move down at each press of that letter. This SUB is not | ' | set up to use a mouse. | ' | - - - - - - - - - - - - - - - - - - - - - - - - | ' | If you press or the SUB will exit and a screen | ' | will be displayed. To find out how to use all the keys, | ' | refer to FKey$ below. | ' +----------------+---------------------------------------------------+ ' | M$() | Menu Item. In main program rediminsion: | ' | | REDIM M$(MaxNum% + 10) | ' +----------------+---------------------------------------------------+ ' | Start% | Which item to hi-light first. | ' +----------------+---------------------------------------------------+ ' | Count% | Count of total menu items. | ' +----------------+---------------------------------------------------+ ' | RegColrFG% | Regular fore ground color. | ' +----------------+---------------------------------------------------+ ' | RegColrBG% | Regular background color. | ' +----------------+---------------------------------------------------+ ' | HiLiteFG% | Hi-light foreground color. | ' +----------------+---------------------------------------------------+ ' | HiLiteBG% | Hi-light background color. | ' +----------------+---------------------------------------------------+ ' | MaxScrRows% | Number of rows to display on screen. | ' +----------------+---------------------------------------------------+ ' | MaxScrCols% | Number of columns to display on screen. | ' +----------------+---------------------------------------------------+ ' | ColumnPointer% | Points to current column in use. | ' +----------------+---------------------------------------------------+ ' | TweenSpace% | Number of spaces between columns. | ' +----------------+---------------------------------------------------+ ' | TableULRow% | Upper left row to place menu. | ' +----------------+---------------------------------------------------+ ' | TableULCol% | Upper left column to place menu. | ' +----------------+---------------------------------------------------+ ' | CurrentRow% | Current row of hi-light item. | ' +----------------+---------------------------------------------------+ ' | CurrentCol% | Current column of hi-light item. | ' +----------------+---------------------------------------------------+ ' | ItemNum% | Menu item number of the hi-lighted item. | ' | | In main program Start% and ItemNum% should be | ' | | the same. | ' +----------------+---------------------------------------------------+ ' | ItemWidth% | Width of menu items. | ' +----------------+---------------------------------------------------+ ' | FKey$ | To exit when an key is pressed, designate | ' | | the keys by placing them between paranthesis. | ' | | Example: FKey$ = "150". This means the SUB will | ' | | exit on pressing , or . The "0" | ' | | means "10". In the main program, indicate the | ' | | keys with ExitCode%. to is | ' | | ExitCode% = 1 to ExitCode% = 10. | ' | | | ' | | Example: | ' | | ------- | ' | | IF ExitCode% = 1 THEN ' | ' | | GOSUB save.screen | ' | | COLOR 15, 1: CLS | ' | | LOCATE 2, 33 | ' | | PRINT "Help Screen" | ' | | DO: LOOP WHILE INKEY$ = "" | ' | | GOSUB restore.screen | ' | | Start% = ItemNum% | ' | | GOTO begin.complete.menu | ' | | END IF | ' +----------------+---------------------------------------------------+ ' | ExitCode% | The exit number as explained below. | ' +--------------------------------------------------------------------+ ' | In the code below this REM (') section, find the area beginning | ' | "loopdeloop" and notice the keys trap below it. In QuickBASIC | ' | it is very easy to trap for any key on the keyboard by using the | ' | CVI command. It is accomplished through the use of a double | ' | DO/LOOP and then a series of IF/THENs (See Example). | ' | | ' | Example: | ' | ------- | ' | COLOR 15, 1: CLS | ' | PRINT "Press or X. To exit, press " | ' | PRINT | ' | DO | ' | DO | ' | Hit$ = INKEY$ | ' | LOOP UNTIL LEN(Hit$) > 0 | ' | Hit% = CVI(Hit$ + CHR$(0)) | ' | IF Hit% = 27 THEN ' | ' | CLS : END | ' | ELSEIF Hit% = 15104 THEN ' | ' | PRINT "F1 - Yeah!" | ' | ELSEIF Hit% = 24 THEN ' or | ' | PRINT "Ctrl-X. Yeah!" | ' | END IF | ' | LOOP | ' | | ' +--------------------------------------------------------------------+ ' | Use the KEYCODE.BAS program below to find the CVI numbers for | ' | the keys you need to trap. | ' +--------------------------------------------------------------------+ ' | ' KeyCode.Bas - By Don Smith. FreeWare and Public Domain Program. | ' | ' | ' | ' +-------------------------------------------------------------+ | ' | ' | 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 15, 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 | ' | | ' +--------------------------------------------------------------------+ FOR EqWidth% = 1 TO Count% M$(EqWidth%) = M$(EqWidth%) + SPACE$(ItemWidth% - LEN(M$(EqWidth%))) NEXT subtop: DivideIt% = Count% \ MaxScrRows% Remainder% = Count% MOD MaxScrRows% IF Remainder% > 0 THEN Remainder% = 1 END IF NumColsPossible% = DivideIt% + Remainder% LeftOver% = Count% MOD MaxScrRows% 'Count of items of last row IF Start% = 1 THEN CurrentRow% = TableULRow% CurrentCol% = TableULCol% ColumnPointer% = 1 ELSE LocateRow% = Start% MOD MaxScrRows% IF LocateRow% = 0 THEN LocateRow% = MaxScrRows% ColumnPointer% = (Start% \ MaxScrRows%) ELSE ColumnPointer% = (Start% \ MaxScrRows%) + 1 END IF CurrentRow% = TableULRow% + LocateRow% - 1 LocateCol% = (Start% \ MaxScrRows%) IF Start% MOD MaxScrRows% > 0 THEN LocateCol% = LocateCol% + 1 END IF IF LocateCol% > MaxScrCols% THEN LocateCol% = LocateCol% - MaxScrCols% FOR Spy% = 1 TO NumColsPossible% IF LocateCol% > MaxScrCols% THEN LocateCol% = LocateCol% - MaxScrCols% END IF IF LocateCol% <= MaxScrCols% THEN EXIT FOR END IF NEXT TheFactor% = ColumnPointer% \ MaxScrCols% IF ColumnPointer% MOD MaxScrCols% = 0 THEN show% = (MaxScrCols% * MaxScrRows%) * (TheFactor% - 1) ELSE show% = (MaxScrCols% * MaxScrRows%) * TheFactor% END IF IF LocateCol% <= 1 THEN CurrentCol% = TableULCol% END IF END IF END IF IF CurrentCol% < TableULCol% THEN CurrentCol% = TableULCol% + ((LocateCol% - 1) * (ItemWidth% + TweenSpace%)) END IF bring.in.display: FOR display% = TableULRow% TO TableULRow% + MaxScrRows% - 1 COLOR RegColrFG%, RegColrBG% LOCATE display%, TableULCol%, 0, 0, 0 show% = show% + 1 IF show% <= Count% THEN PRINT M$(show%) + SPACE$(TweenSpace%); ELSE PRINT SPACE$(ItemWidth% + TweenSpace%); END IF FOR ExecuteNext% = 1 TO MaxScrCols% - 1 IF show% + (ExecuteNext% * MaxScrRows%) <= Count% THEN IF LEN(M$(show% + (ExecuteNext% * MaxScrRows%))) = ItemWidth% THEN PRINT M$(show% + (ExecuteNext% * MaxScrRows%)) + SPACE$(TweenSpace%); ELSEIF LEN(M$(show% + (ExecuteNext% * MaxScrRows%))) = 0 THEN PRINT SPACE$(ItemWidth% + TweenSpace%); END IF ELSE IF Count% > (MaxScrRows% * MaxScrCols%) THEN PRINT SPACE$(ItemWidth% + TweenSpace%); END IF END IF NEXT NEXT COLOR HiLiteFG%, HiLiteBG% LOCATE CurrentRow%, CurrentCol%, 0, 0, 0 PRINT M$(ItemNum%) loopdeloop: DO DO HitKey$ = INKEY$ LOOP UNTIL LEN(HitKey$) > 0 Hit% = CVI(HitKey$ + CHR$(0)) LOCATE CurrentRow%, CurrentCol%, 0, 0, 0 COLOR RegColrFG%, RegColrBG% PRINT M$(ItemNum%); IF Hit% = 27 THEN ' ExitCode% = 27 EXIT SUB ELSEIF Hit% = 13 THEN ' ExitCode% = 13 EXIT SUB ELSEIF Hit% = 20480 THEN ' IF LeftOver% = 0 AND ItemNum% = Count% THEN CurrentRow% = TableULRow% - 1 ItemNum% = Count% - MaxScrRows% END IF IF ItemNum% < Count% THEN CurrentRow% = CurrentRow% + 1 ItemNum% = ItemNum% + 1 IF CurrentRow% = TableULRow% + MaxScrRows% THEN CurrentRow% = TableULRow% ItemNum% = ItemNum% - MaxScrRows% END IF ELSE CurrentRow% = TableULRow% ItemNum% = Count% - LeftOver% + 1 END IF ELSEIF Hit% = 18432 THEN ' CurrentRow% = CurrentRow% - 1 ItemNum% = ItemNum% - 1 IF CurrentRow% = TableULRow% - 1 THEN CurrentRow% = TableULRow% + MaxScrRows% - 1 ItemNum% = ItemNum% + MaxScrRows% IF ItemNum% > Count% THEN ItemNum% = Count% CurrentRow% = TableULRow% + LeftOver% - 1 END IF END IF ELSEIF Hit% = 19712 THEN ' IF ItemNum% <= Count% - LeftOver% THEN CurrentCol% = CurrentCol% + TweenSpace% + ItemWidth% ItemNum% = ItemNum% + MaxScrRows% ColumnPointer% = ColumnPointer% + 1 IF ItemNum% > Count% THEN ItemNum% = Count% IF LeftOver% = 0 THEN CurrentCol% = CurrentCol% - (TweenSpace% + ItemWidth%) CurrentRow% = TableULRow% + MaxScrRows% - 1 ItemNum% = Count% ColumnPointer% = ColumnPointer% - 1 ELSEIF LeftOver% > 0 THEN CurrentRow% = TableULRow% + LeftOver% - 1 END IF END IF END IF IF ColumnPointer% > MaxScrCols% THEN Start% = ItemNum% show% = 0 ColumnPointer% = 0 GOTO subtop END IF ELSEIF Hit% = 19200 THEN ' IF ColumnPointer% <= 0 THEN ColumnPointer% = 1 END IF IF ColumnPointer% > 1 THEN CurrentCol% = CurrentCol% - (TweenSpace% + ItemWidth%) ItemNum% = ItemNum% - MaxScrRows% ColumnPointer% = ColumnPointer% - 1 END IF IF ColumnPointer% >= MaxScrCols% THEN ColumnPointer% = 0 Start% = ItemNum% show% = 0 GOTO subtop END IF ELSEIF Hit% = 18176 THEN ' CurrentRow% = 0 CurrentCol% = 0 show% = 0 ItemNum% = 1 Start% = 1 GOTO subtop ELSEIF Hit% = 20224 THEN ' show% = 0 ItemNum% = Count% Start% = Count% CurrentCol% = 0 GOTO subtop ELSEIF Hit% = 20736 THEN ' ItemNum% = ItemNum% + (MaxScrRows% * MaxScrCols%) IF ItemNum% > Count% THEN ItemNum% = Count% END IF Start% = ItemNum% CurrentCol% = 0 show% = 0 GOTO subtop ELSEIF Hit% = 18688 THEN ' ItemNum% = ItemNum% - (MaxScrRows% * MaxScrCols%) IF ItemNum% <= 0 THEN ItemNum% = 1 END IF Start% = ItemNum% CurrentCol% = 0 show% = 0 GOTO subtop 'PRESS: Letters A - Z (or a - z), Numbers 0 - 9, ' Exclamation , or Underline <_>. ELSEIF Hit% > 64 AND Hit% < 91 OR Hit% > 96 AND Hit% < 123 OR Hit% > 47 AND Hit% < 58 OR Hit% = 33 OR Hit% = 95 THEN IF Hit% > 96 AND Hit% < 123 THEN Hit% = Hit% - 32 END IF FOR XYZ% = 1 TO Count% Letr$ = LEFT$(M$(XYZ%), 1) IF XYZ% = Count% AND ASC(Letr$) <> Hit% THEN show% = 0 GOTO subtop ELSEIF ASC(Letr$) = Hit% THEN EXIT FOR END IF NEXT FOR YYY% = 1 TO Count% CurrentLetr$ = LEFT$(M$(ItemNum%), 1) IF CurrentLetr$ <> FindLetr$ THEN TryLetters% = 0 END IF NEXT TryLetters% = TryLetters% + 1 FOR zzz% = TryLetters% TO Count% FindLetr$ = LEFT$(M$(zzz%), 1) IF ASC(FindLetr$) = Hit% THEN Start% = zzz% TryLetters% = zzz% ItemNum% = Start% ColumnPointer% = 0 show% = 0 CurrentCol% = 0 IF zzz% = Count% THEN ItemNum% = Count% TryLetters% = 0 END IF GOTO subtop END IF IF zzz% = Count% THEN zzz% = 0 END IF NEXT ELSEIF Hit% > 15103 AND Hit% < 17409 THEN 'F1 - F10 IdentKey$ = STR$(((Hit% - 15104) \ 256) + 1) IdentKey$ = LTRIM$(RTRIM$(IdentKey$)) IF IdentKey$ = "10" THEN IdentKey$ = "0" END IF IF INSTR(FKey$, IdentKey$) > 0 THEN IF IdentKey$ = "0" THEN ExitCode% = 10 EXIT SUB ELSE ExitCode% = VAL(IdentKey$) EXIT SUB END IF END IF END IF LOCATE CurrentRow%, CurrentCol%, 0, 0, 0 COLOR HiLiteFG%, HiLiteBG% PRINT M$(ItemNum%); LOOP END SUB