SUB Rolidex (M$(), TopRow%, Row%, FirstCol%, Col%, NumOfCols%, NumOfRows%, ColrFG%, ColrBG%, BoxColrFG%, BoxColrBG%, VertInterval%, HorizInterval%, Box%, MaxNum%, FKeys$, ExitCode%) ' +-------------------------------------------------------------------+ ' | Rolidex Program | ' +-------------------------------------------------------------------+ ' | Rolidex.Bas was written by Don Smith on 09/01/2002 and it is | ' | Public Domain, FreeWare. Other programmers need not name me | ' | as author of the SUB. EMail: smithdonb@earthlink.net | ' | | ' | Rolidex has 203 lines, not counting remark lines (') (REM). | ' +----------------+--------------------------------------------------+ ' | M$() | The menu items as used here are letters (A-Z), | ' | | but they could be used for other items as well. | ' | | Days of the month, for example. | ' +----------------+--------------------------------------------------+ ' | TopRow% | The top row to begin placing the menu items (M$) | ' +----------------+--------------------------------------------------+ ' | Row% | Set Row to Row% = TopRow% in main part of | ' | | program. Otherwise the program uses this to | ' | | enter and reenter as the user presses | ' | | or other keys, such as . | ' +----------------+--------------------------------------------------+ ' | FirstCol% | The first column to place menu items (M$). | ' +----------------+--------------------------------------------------+ ' | Col% | Set Col to Col% = FirstCol% in main program. | ' | | Otherwise, the program keeps track of Col%. | ' +----------------+--------------------------------------------------+ ' | NumOfCols% | Number of columns to place on screen. | ' +----------------+--------------------------------------------------+ ' | NumOfRows% | Number of rows to place on screen. | ' | | As used here, there are 6 colunns and | ' | | 5 rows. That means that the last row, | ' | | row 5, only has 3 items, whereas the first | ' | | 4 rows have 6 items. Special provision is | ' | | made for this problem under "down.arrow", | ' | | "up.arrow", "right.arrow" and "left.arrow". | ' | | If you change to other columns and rows, | ' | | you will need to hack those subroutines. | ' +----------------+--------------------------------------------------+ ' | ColrFG% | Foreground color of menu items. | ' +----------------+--------------------------------------------------+ ' | ColrBG% | Back ground color of menu items. | ' +----------------+--------------------------------------------------+ ' | BoxColrFG% | Foreground color of cursor box. | ' +----------------+--------------------------------------------------+ ' | BoxColrBG% | Back ground color of cursor box. | ' +----------------+--------------------------------------------------+ ' | VertInterval% | Vertical interval between menu items. | ' +----------------+--------------------------------------------------+ ' | HorizInterval% | Horizontal interval between menu items. | ' +----------------+--------------------------------------------------+ ' | Box% | Set Box% = 1 in main progam. Thereafter, | ' | | the program keeps track of Box%. | ' +----------------+--------------------------------------------------+ ' | MaxNum% | Maximum number of menu items. Must REDIM | ' | | M$ (menu items) with this in main program. | ' | | Example: REDIM M$(MaxNum%) | ' +----------------+--------------------------------------------------+ ' | FKeys$ | I wrote a routine into the SUB Rolidex to handle | ' | | the keys, to . The routine | ' | | automatically sets an ExitCode% number and exits | ' | | the SUB when the set keys are pressed. You | ' | | should set the key(s) in the main program, | ' | | using FKeys$ = "". If, for example, you have | ' | | FKeys$ = "150" then the SUB will set | ' | | and . When one of these keys are | ' | | pressed, the SUB will set ExitCode% 1, 5 or 10 | ' | | and EXIT SUB. By the way, the "0" in "150" is | ' | | used for . For other special use keys, | ' | | read ExitCode% below. | ' +----------------+--------------------------------------------------+ ' | ExitCode% | ExitCode% is set by program to reflect | ' | | the user pressing or . | ' | | is ExitCode% = 13 and is | ' | | ExitCode% = 27. | ' | | | ' | | to are ExitCode% = 1 to 10. | ' | | | ' | | To set other special keys, use KEYCODE.BAS | ' | | below to find the special CVI number for your | ' | | key(s). Example: is 21504. In the | ' | | SUB Rolidex, find: | ' | | | ' | | DO | ' | | DO | ' | | Hit$ = INKEY$ | ' | | LOOP UNTIL LEN(Hit$) > 0 | ' | | Hit% = CVI(Hit$ + CHR$(0)) | ' | | | ' | | This CVI number so determined will be able to | ' | | be used in a series of IFs and ELSEIFs. To | ' | | set up , use: | ' | | | ' | | (Goes below double DO:LOOP | ' | | ELSEIF Hit% = 21504 THEN ' | ' | | (code goes here) | ' | | | ' | | Find the double DO:LOOPs below and find out | ' | | how I wrote the code. | ' +----------------+--------------------------------------------------+ ' | Refer to the "pre-set amounts" just below KEYCODE.BAS for | ' | directions on how to adjust the cursor box. | ' +-------------------------------------------------------------------+ ' +-------------------------------------------------------------------+ ' | 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. | | ' | ' +-------------------------------------------------------------+ | ' +-------------------------------------------------------------------+ ' | <- ("Tear off" first 3 characters) | ' | ("Tear off" last character) -> | ' | | ' | 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 | ' | | ' +-------------------------------------------------------------------+ '=======================pre-set amounts===============================+ '| ADJUST CURSOR BOX HERE (1 & 2): | '+-------------------------------------+ BoxWidth% = HorizInterval% - 3 '| 1. Adjust width of cursor box here. | '| Change the 3 to 4, 5 or 6. See | '| ColLessAmt% just below. | '| (Note: These amounts are set here| '| and not in the main program) | '-------------------------------+-------------------------------------+ ColLessAmt% = 5 '| 2. Set the (Col)column (of menu | '| items), (Less) the (Amt) amount | '| of spaces to begin placing the | '| box. Change the 5 to 4 or 3. | '| For both BoxWidth% & ColLessAmt%,| '| try: (4/4, 5/4, 6/3 -> see below)| '| | '| BoxWidth% = HorizInterval% - 4 | '| ColLessAmt% = 4 | '| OR | '| BoxWidth% = HorizInterval% - 5 | '| ColLessAmt% = 4 | '| OR | '| BoxWidth% = HorizInterval% - 6 | '| ColLessAmt% = 3 | '| | '----------------------other pre-set amounts--------------------------+ BottRow% = TopRow% + (VertInterval% * (NumOfRows% - 2)) '| LastCol% = FirstCol% + ((NumOfCols - 1) * HorizInterval%) '| SetHoriz% = HorizInterval% '| PlantRow% = TopRow% '| '=====================================================================+ COLOR ColrFG%, ColrBG% CountHoriz% = 0 FOR ColItems% = 1 TO NumOfRows% FOR RowItems% = 1 TO NumOfCols% MenuItems% = MenuItems% + 1 LOCATE PlantRow%, FirstCol% + CountVert% CountVert% = CountVert% + 13 PRINT M$(MenuItems%); IF MenuItems% = MaxNum% THEN PlantRow% = TopRow% EXIT FOR END IF NEXT PlantRow% = PlantRow% + VertInterval% CountVert% = 0 NEXT GOSUB place.box DO DO Hit$ = INKEY$ LOOP UNTIL LEN(Hit$) > 0 Hit% = CVI(Hit$ + CHR$(0)) LOCATE , , 0 IF Hit% = 27 THEN ' ExitCode% = 27 EXIT SUB ELSEIF Hit% > 64 AND Hit% < 91 OR Hit% > 96 AND Hit% < 123 THEN 'Letters A-Z and a-z IF Hit% > 64 AND Hit% < 91 THEN Box% = Hit% - 64 ELSEIF Hit% > 96 AND Hit% < 123 THEN Box% = Hit% - 96 END IF GOSUB clear.box GOSUB letter.select GOSUB place.box ELSEIF Hit% = 13 THEN ' ExitCode% = 13 EXIT SUB ELSEIF Hit% = 20480 THEN ' GOSUB clear.box GOSUB down.arrow GOSUB place.box ELSEIF Hit% = 18432 THEN ' GOSUB clear.box GOSUB up.arrow GOSUB place.box ELSEIF Hit% = 19712 THEN ' GOSUB clear.box GOSUB right.arrow GOSUB place.box ELSEIF Hit% = 19200 THEN ' GOSUB clear.box GOSUB left.arrow GOSUB place.box 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(FKeys$, IdentKey$) > 0 THEN IF IdentKey$ = "0" THEN ExitCode% = 10 EXIT SUB ELSE ExitCode% = VAL(IdentKey$) EXIT SUB END IF END IF END IF LOOP '================================================================================= ' If you have a rolidex-style screen different from the one establish ' here, be careful with this Line Label "letter.select". You'll need ' to change the Row% and Col% numbers to fit your new rolidex screen. '================================================================================= letter.select: SELECT CASE Box% CASE 1 TO 6 Row% = 11 CASE 7 TO 12 Row% = 13 CASE 13 TO 18 Row% = 15 CASE 19 TO 24 Row% = 17 CASE 25 TO 26 Row% = 19 END SELECT SELECT CASE Box% CASE 1, 7, 13, 19, 25 Col% = 8 CASE 2, 8, 14, 20, 26 Col% = 21 CASE 3, 9, 15, 21 Col% = 34 CASE 4, 10, 16, 22 Col% = 47 CASE 5, 11, 17, 23 Col% = 60 CASE 6, 12, 18, 24 Col% = 73 END SELECT RETURN place.box: COLOR 11, 1 LOCATE 20, 57 IF Box% = 27 THEN COLOR 14, 1: PRINT " Exit " ELSE PRINT "Letter "; LOCATE 20, 64: COLOR 15, 1: PRINT CHR$(Box% + 64); END IF COLOR 11, 1: LOCATE 20, 69: PRINT "Item " COLOR 15, 1 LOCATE 20, 74: PRINT RTRIM$(LTRIM$(STR$(Box%))) + " "; COLOR BoxColrFG%, BoxColrBG% LOCATE Row% - 1, Col% - ColLessAmt% PRINT CHR$(218) + STRING$(BoxWidth% - 1, CHR$(196)) + CHR$(191); LOCATE Row%, Col% - ColLessAmt% PRINT CHR$(179); LOCATE Row%, Col% + BoxWidth% - ColLessAmt% PRINT CHR$(179); LOCATE Row% + 1, Col% - ColLessAmt%, 0 PRINT CHR$(192) + STRING$(BoxWidth% - 1, CHR$(196)) + CHR$(217); RETURN clear.box: COLOR ColrFG%, ColrBG% LOCATE Row% - 1, Col% - ColLessAmt% PRINT " " + STRING$(BoxWidth% - 1, " ") + " "; LOCATE Row%, Col% - ColLessAmt% PRINT " "; LOCATE Row%, Col% + BoxWidth% - ColLessAmt% PRINT " "; LOCATE Row% + 1, Col% - ColLessAmt%, 0 PRINT " " + STRING$(BoxWidth% - 1, " ") + " "; RETURN down.arrow: 'next 5 lines for last row info IF Row% = BottRow% + VertInterval% THEN Box% = Box% - (NumOfCols% * (NumOfRows% - 1)) Row% = TopRow% RETURN END IF IF Row% = BottRow% THEN IF Row% = BottRow% AND Col% = FirstCol% OR Col% = FirstCol% + SetHoriz% OR Col% = FirstCol% + SetHoriz% + SetHoriz% THEN Row% = Row% + VertInterval% Box% = Box% + NumOfCols% RETURN ELSEIF Row% = BottRow% THEN Box% = Box% - (NumOfCols% * (NumOfRows% - 2)) Row% = TopRow% END IF ELSEIF Row% = TopRow% THEN Box% = Box% + NumOfCols% Row% = Row% + VertInterval% ELSEIF Row% > TopRow% OR Row% < BottRow% THEN Box% = Box% + NumOfCols% Row% = Row% + VertInterval% END IF RETURN up.arrow: 'next 5 lines for last row info IF Row% = TopRow% AND Col% = FirstCol% OR Row% = TopRow% AND Col% = FirstCol% + SetHoriz% OR Row% = TopRow% AND Col% = FirstCol% + SetHoriz% + SetHoriz% THEN Row% = BottRow% + VertInterval% Box% = Box% + (NumOfCols% * (NumOfRows% - 1)) RETURN END IF IF Row% = BottRow% THEN Box% = Box% - NumOfCols% Row% = Row% - VertInterval% ELSEIF Row% = TopRow% THEN Box% = Box% + (NumOfCols% * (NumOfRows% - 2)) Row% = BottRow% ELSEIF Row% > TopRow% OR Row% < BottRow% THEN Box% = Box% - NumOfCols% Row% = Row% - VertInterval% END IF RETURN right.arrow: 'next 15 lines for last row info: IF Row% = BottRow% + VertInterval% THEN IF Col% = FirstCol% THEN Col% = FirstCol% + SetHoriz% ELSEIF Col% = FirstCol% + SetHoriz% THEN Col% = FirstCol% + SetHoriz% + SetHoriz% ELSEIF Col% = FirstCol% + SetHoriz% + SetHoriz% THEN Col% = FirstCol% END IF Box% = Box% + 1 IF Box% = 28 THEN Box% = 25 Col% = FirstCol% END IF RETURN END IF IF Col% = LastCol% THEN Box% = Box% - NumOfCols% + 1 Col% = FirstCol% ELSEIF Col% = FirstCol% THEN Box% = Box% + 1 Col% = Col% + SetHoriz% ELSEIF Col% > FirstCol% OR Col% < LastRow% THEN Box% = Box% + 1 Col% = Col% + SetHoriz% END IF RETURN left.arrow: 'next 12 lines for last row info IF Row% = BottRow% + VertInterval% THEN IF Col% = FirstCol% THEN Box% = 28 Col% = FirstCol% + SetHoriz% + SetHoriz% ELSEIF Col% = FirstCol% + SetHoriz% THEN Col% = FirstCol% ELSEIF Col% = FirstCol% + SetHoriz% + SetHoriz% THEN Col% = FirstCol% + SetHoriz% END IF Box% = Box% - 1 RETURN END IF IF Col% = FirstCol% THEN Box% = Box% + NumOfCols% - 1 Col% = LastCol% ELSEIF Col% > FirstCol% OR Col% < LastCol% THEN Box% = Box% - 1 Col% = Col% - SetHoriz% ELSEIF Col% = LastCol% THEN Box% = Box% - 1 Col% = Col% - SetHoriz% - SetHoriz% END IF RETURN END SUB