home *** CD-ROM | disk | FTP | other *** search
- ' MNULIN.SUB -- MSDOS QuickBASIC Color line menu subroutine
- ' by David L. Poskie Madison, WI
-
- '| Reads up to 11 one-line menus, up to 9 selections per menu from DATA lines
- '| located in the calling program.
- '| Load menus in MENU$(n,n) by GOSUB LOAD.MNU , returns MAX.MNU = # of menus.
- '| LOCATE cursor before calling menu, then call a menu by:
- '| setting MNU = (0 to 10) : GOSUB MNULIN -- evaluate K.CODE on RETURN.
- '| Quit will always return K.CODE = -21. I use this number because <ESC> also
- '| returns -21. Thus, you can bail out of a menu with <ESC>. No other
- '| evaluation is made -- you will get any out of bounds numbers and must
- '| check for these in the main program.
- '|
- '| Saves foreground & background colors, restoring them after input.
- '|
- '| Vars: MENU$(),MNU(),K.CODE,MAX.MNU,MNU,NUM.MNU,NUM.SEL(),SEL,FG,BG,BLANK.
-
- ' Subroutine to read DATA into MENU$(MNU , SEL),
- ' loading all the menus and prompts.
- LOAD.MNU:
-
- RESTORE MENU.DAT ' In case the pointer is
- FOR MNU = 0 TO 10 ' somewhere else
- FOR SEL = 0 TO 10
- READ MENU$(MNU , SEL)
-
- ' Look for end of ONE menu symbol
- IF MENU$(MNU , SEL) = "*" _
- THEN NUM.SEL(MNU) = SEL - 1 : _
- GOTO LOAD.MNU.LOOP
- ' NUM.SEL(MNU) holds number of selections
-
- ' Look for end of ALL menus symbol
- IF MENU$(MNU , SEL) = "$" _
- THEN NUM.MNU = MNU - 1 : _
- GO TO LOAD.MNU.XIT
-
- NEXT SEL
-
- ' One Menu is read
- LOAD.MNU.LOOP:
-
- NEXT MNU
-
- ' All Menus are read
- LOAD.MNU.XIT:
-
- MAX.MNU = MNU - 1 ' Maximum number of menus
- RETURN
- '____________________END OF LOAD.MNU SUBROUTINE______________________
-
- 'Subroutine to print the menu line and get a response
- MNULIN:
-
- ' Read foreground color
- FG = ((SCREEN (1 , 1 , 1)) MOD 16)
-
- ' Read background color
- BG = (((SCREEN (1 , 1 , 1)) - FG) / 16) MOD 128
-
- ' Set blank space between selections
- BLANK = 0
-
- FOR I = 0 TO NUM.SEL(MNU)
- BLANK = BLANK + LEN(STR$(I)) + LEN(MENU$(MNU , I)) + 2
- NEXT I
-
- BLANK = INT((80 - BLANK) / NUM.SEL(MNU) - 1)
-
- ' Case of a negative number
- IF BLANK < 0 _
- THEN BLANK = 0
-
- ' Case of protecting BLANK = 1
- IF BLANK > 1 _
- THEN BLANK = INT(BLANK / 2)
-
- ' Print menu line
- COLOR 0 , 7
-
- FOR I = 1 TO NUM.SEL(MNU)
- PRINT SPC(BLANK); STR$(I); SPC(BLANK); MENU$(MNU,I); " █";
- NEXT I
-
- ' Print prompt
- COLOR 28 , 0
- PRINT " « ";
- COLOR 12
- PRINT MENU$(MNU , 0);
-
- GOSUB GETKEY.CLEAR
-
- K.CODE = K.CODE - 48 ' Adjust to track with number
-
- ' Set Quit Command to -21
- IF K.CODE = NUM.SEL(MNU) _
- THEN K.CODE = -21 ' Allows bailout on <ESC>
-
- ' Restore colors & go
- COLOR FG , BG
-
- RETURN
- '____________________END OF MNULIN SUBROUTINE______________________
-
- '>>>>> Physical EOF MNULIN.SUB