home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / Basic / TOPMENU.ZIP / TOPMENU.BAS
Encoding:
BASIC Source File  |  1988-08-11  |  14.6 KB  |  612 lines

  1. '========================================================================
  2. '                                 Top.Menu
  3. '
  4. '    Written By:  Glenn Miller (Not The Band Leader)
  5. '                 Route 8 Box 492-A
  6. '                 Asheboro, North Carolina  27203
  7. '
  8. '            On:  August 5, 1988
  9. '
  10. '
  11. '    This Program is " FreeWare "  use it, abuse it, loose-it..etc...
  12. '
  13. '    Please Don't send me money for using this routine, because it would
  14. '    only be used by me to buy more computer stuff.
  15. '========================================================================
  16. '
  17. 'This routine was created as an easy means to set up a menu operated system,
  18. 'without having to deal with passing "zillions" of varables to a subroutine.
  19. '
  20. 'This is in NO way intended to replace any of the fine utilities available
  21. 'but to be considered as a simpler (and less definable) substitute.
  22. '
  23. 'Okay..Enough of that..Now on to this....
  24. '
  25. '
  26. 'As you can see in the DECLARE statement on the 1st line of this program there
  27. 'are only 4 varables that need to be passed to the subroutine..
  28. '
  29. 'and here they are.....
  30. '
  31. '
  32. '  SEL   Returns containing the number of the selection that was selected.
  33. '
  34. '  SEL$  an arry of strings containing all the menu and submenu selections
  35. '        as well as the help line (line 25)
  36. '
  37. '  FGC   Fore Ground Color of the Menus
  38. '
  39. '  BGC   Back Ground Color of the Menus
  40. '
  41. '  MSG$  a string that will be centered on the Top Line of the Menu.
  42. '        If MSG$="" then No Message is displayed on the top line.
  43. '
  44. 'Heres the Details..........
  45. '
  46. 'This Menu system is a bar type with sub menus.
  47. 'There can be up to 9 selections per sub menu.
  48. 'There can be as many Selections on the Top Bar That you can fit on it
  49. 'and these DO NOT have to be the same length.
  50. '
  51. '
  52. 'The KEY to this menu system is the SEL$() array.
  53. '
  54. 'This array should be dimensioned as DIM SEL$(x,10) in the start of your
  55. 'program, Where x=number of Top Bar Selections you will have.
  56. '
  57. 'Array SEL$(x,0) needs to contain the Selection Names For the Top Bar.
  58. '
  59. 'Arrays SEL$(x,1) thru SEL$(x,9) contain the Selection Names For the
  60. 'sub menu under the SEL$(x,0) Name.
  61. '
  62. 'Array SEL$(x,10) needs to contain the HELP message that will be displayed
  63. 'on line 25. (if you want one.)
  64. '
  65. '
  66. 'Example:  To Set up a Selection called "DOS" and have 3 sub selections
  67. '          called:
  68. '
  69. '                 Exit To Dos
  70. '                 Shell To Dos
  71. '                 Enter Dos Commands
  72. '
  73. '         with a Help Message of:  What Do You Want!
  74. '
  75. 'The arrays would be:
  76. '
  77. '         SEL$(0,0)=" Dos "
  78. '         SEL$(0,1)=" Exit To Dos "
  79. '         SEL$(0,2)=" Shell To Dos "
  80. '         SEL$(0,3)=" Enter Dos Commands "
  81. '         SEL$(0,4)=""
  82. '         SEL$(0,10)="What Do You Want!"
  83. '       
  84. '
  85. ' !!!!! NOTICE !!!!!
  86. '
  87. '       See How SEL$(0,4)=""
  88. '
  89. '       You MUST always define the next array AFTER the last one you want
  90. '       to use as "" (Nul).
  91. '
  92. '       This makes it work right!..Okay..OK
  93. '
  94. '
  95. 'Define all the Selections you need by this method.
  96. 'Of course you will change to the next array..ie 1,2,3...etc. instead of 0.
  97. '
  98. '
  99. '
  100. 'Running the program........
  101. '
  102. 'Once you have setup all the SEL$() your ready to go.
  103. '
  104. 'The Top Bar Selections can be selected by 2 different ways.....
  105. '
  106. ' 1 - Use The Left-Right cursor Keys to move to the desired selection.
  107. ' 2 - Press the Key of the 1st letter of a selection.
  108. '
  109. '     Note: If more than one selection has the same starting letter the
  110. '           program will move to the next selection when that same letter
  111. '           key is pressed again. I call this a "round-robin" display but I
  112. '           really dont know why.
  113. '
  114. '
  115. 'The Sub selections can be selected 2 different ways...
  116. '
  117. ' 1 - Use the Up-Down cursor keys to move to the desired selection and press
  118. '     the Enter Key.
  119. ' 2 - Enter the Number of the selection.(no enter key needed)
  120. '
  121. '
  122. '
  123. '
  124. 'What you get back for all your trouble........
  125. '
  126. 'The SEL variable returns to you with a number containing the Selection that
  127. 'was selected. (wheeeee...)
  128. '
  129. ' If the user pressed the "Esc" Key SEL will be -1. (neg.1)
  130. ' else heres what you get.
  131. '
  132. '
  133. ' The number is determined by: (Top Bar Selection Number *10) + selected sub#
  134. '
  135. 'Example:  If the user selected item# 5 from the first Top Bar selection the
  136. '          number would be: 5.
  137. '
  138. '          First Top Bar number = 0     SEL$(0,x)
  139. '
  140. '          0 * 10 = 0  + 5      = 5
  141. '
  142. '
  143. '    If item# 5 was selected from the 5th Top Bar the number would be: 45
  144. '
  145. '          5th  Top Bar Number  = 4    SEL$(4,x)
  146. '
  147. '          4 * 10 = 40 + 5      = 45
  148. '
  149. '
  150. '
  151. '
  152. ' Below is a short program using the TOP MENU subroutine this will help
  153. ' show you how it works and the numbers that will be returned.
  154. '
  155. ' Thats about it for now....so....
  156. ' Waiter!.....TOP.MENU......please!
  157. '========================================================================
  158.  
  159. DECLARE SUB Top.Menu (sel, sel$(), fgc!, bgc!, msg$)
  160.  
  161. DIM sel$(6, 10)                 'remember this?
  162.  
  163.  
  164.  
  165. '====== Define the Top Bar Selections
  166.  
  167. sel$(0, 0) = " Directories "
  168. sel$(1, 0) = " Dos "
  169. sel$(2, 0) = " Set Time "
  170. sel$(3, 0) = " Exit "
  171. sel$(4, 0) = " Set Date "
  172. sel$(5, 0) = " HELP! "
  173.  
  174. '===== Define Help messages for line 25
  175.  
  176. sel$(0, 10) = "Display The Directory For The Selected Drive"
  177. sel$(1, 10) = "Use This To Interact With Dos"
  178. sel$(2, 10) = "Press Enter To Set The Systems TIME"
  179. sel$(3, 10) = "Press Enter To Return To System"
  180. sel$(4, 10) = "Press Enter To Set The Systems DATE"
  181.  
  182. sel$(5, 10) = ""   'no message for HELP! selection
  183.  
  184.  
  185. '===== Define Sub Selections For  "Directories" (0,0)
  186.  
  187. sel$(0, 1) = " Display File Names For Current Directory "
  188. sel$(0, 2) = " Display File Names For 'C:\' Drive "
  189. sel$(0, 3) = " Display File Names For 'A:\' Drive "
  190.  
  191. sel$(0, 4) = ""
  192.  
  193.  
  194. '===== Define Sub Selections For  "Dos" (1,0)
  195.  
  196. sel$(1, 1) = " Exit To Dos "
  197. sel$(1, 2) = " Shell To Dos "
  198.  
  199. sel$(1, 3) = ""
  200.  
  201.  
  202. '==== NO sub selections for (2,0) (3,0) (4,0) (5,0)
  203.  
  204. sel$(2, 1) = ""
  205. sel$(3, 1) = ""
  206. sel$(4, 1) = ""
  207. sel$(5, 1) = ""
  208.  
  209.  
  210. '===== Define Top Row Message
  211.  
  212. msg$ = " Use Cursor/Letter/Number Keys To Make Selection "
  213.  
  214.  
  215. '===== Define Colors
  216.  
  217. begin: fgc = 7
  218.        bgc = 1
  219.  
  220.  
  221. '===== Make Call to Top.Menu =============================================
  222.  
  223.        CALL Top.Menu(sel, sel$(), fgc!, bgc!, msg$)
  224.  
  225. '===== Do the desired Selection
  226. '
  227. 'if its 'Esc' then end
  228.  
  229.       IF sel = -1 THEN END
  230.  
  231.  
  232.       SELECT CASE sel
  233.  
  234.  
  235.              CASE IS = 1
  236.  
  237.                 CLS
  238.                 LOCATE 1, 1
  239.                 SHELL "dir /p"
  240.                 PRINT "Press Any Key . . .";
  241.                 a$ = INPUT$(1)
  242.                 GOTO begin
  243.  
  244.              CASE IS = 2
  245.  
  246.                 CLS
  247.                 LOCATE 1, 1
  248.                 SHELL "dir c:\ /p"
  249.                 PRINT "Press Any Key . . .";
  250.                 a$ = INPUT$(1)
  251.                 GOTO begin
  252.  
  253.              CASE IS = 3
  254.  
  255.                 CLS
  256.                 LOCATE 1, 1
  257.                 SHELL "dir a:\ /p"
  258.                 PRINT "Press Any Key . . .";
  259.                 a$ = INPUT$(1)
  260.                 GOTO begin
  261.  
  262.  
  263.              CASE IS = 11
  264.  
  265.                 CLS
  266.                 LOCATE 1, 1
  267.                 SYSTEM
  268.  
  269.              CASE IS = 12
  270.  
  271.                 CLS
  272.                 LOCATE 1, 1
  273.                 PRINT "Enter EXIT To Return To Menu"
  274.                 SHELL
  275.                 GOTO begin
  276.  
  277.              CASE IS = 21
  278.  
  279.                 CLS
  280.                 LOCATE 10, 1
  281.               
  282.                 SHELL "time"
  283.                 GOTO begin
  284.  
  285.              CASE IS = 31
  286.  
  287.                 CLS
  288.                 LOCATE 1, 1
  289.                 SYSTEM
  290.                 
  291.              CASE IS = 41
  292.  
  293.                 CLS
  294.                 LOCATE 10, 1
  295.               
  296.                 SHELL "date"
  297.                 GOTO begin
  298.  
  299.              CASE IS = 51
  300.  
  301.                 LOCATE 10, 10
  302.                 PRINT "We All Need Help Now And Then...Press a Key";
  303.                 a$ = INPUT$(1)
  304.                 GOTO begin
  305.                 
  306.              CASE ELSE
  307.                 GOTO begin
  308.       END SELECT
  309.  
  310. SUB Top.Menu (sel, sel$(), fgc, bgc, msg$)
  311. DIM a(20)
  312.       
  313.        s$ = ""
  314.        a = 0
  315.  
  316. '================== clr screen
  317.  
  318.        COLOR fgc, bgc
  319.       
  320.        FOR i = 1 TO 25
  321.          LOCATE i, 1
  322.          PRINT STRING$(80, "░");
  323.        NEXT
  324.      
  325. '================== init line 25  
  326.       
  327.        LOCATE 25, 1
  328.        COLOR bgc, fgc
  329.        PRINT SPACE$(80);
  330.        COLOR fgc, bgc
  331.  
  332. ' ===== get the length of each sel$
  333. ' ===== and get the 1st character of each sel$ and build a string of them 
  334. ' ===== this string is used to select based on letters. 
  335. ' ===== end when sel$="" 
  336.       
  337.        i = -1
  338.        DO
  339.           i = i + 1
  340.           a(i) = LEN(sel$(i, 0))
  341.           z$ = LTRIM$(sel$(i, 0))
  342.           s$ = s$ + UCASE$(LEFT$(z$, 1))
  343.        LOOP WHILE sel$(i, 0) <> ""
  344.         
  345. '===== fix sel to the right number of selections     
  346.       
  347.        sel = i - 1
  348.    
  349. '==== print the top message row 
  350. '====if no message then make top row a line else center the message on the top 
  351. '    
  352. '    
  353.        LOCATE 1, 1
  354.        COLOR fgc, bgc
  355.        t = INT((78 - LEN(msg$)) / 2)
  356.        IF t * 2 + LEN(msg$) < 78 THEN f$ = STRING$((78 - (t * 2 + LEN(msg$))), "─") ELSE f$ = ""
  357.        PRINT "┌" + STRING$(t, "─") + msg$ + f$ + STRING$(t, "─") + "┐";
  358.       
  359. '===== print blank line as middle row 
  360.  
  361.        PRINT "│" + SPACE$(78) + "│";
  362.        
  363.      
  364. '===== print selections on middle row
  365.  
  366.        LOCATE 2, 2
  367.        FOR i = 0 TO sel
  368.          PRINT sel$(i, 0);
  369.        NEXT
  370.   
  371. '===== print bottom row  of box
  372.       
  373.        LOCATE 3, 1
  374.        PRINT "└" + STRING$(78, "─") + "┘";
  375.  
  376. '===== init varables   
  377.        subsel = 1
  378.        subnum = 1
  379.        zold = 2
  380.        s = 0
  381.        x = 2
  382.  
  383. '===== display sub menu
  384.  
  385.   GOSUB dis.sub
  386.  
  387.        
  388. '  
  389. '===== highlite selection on bar
  390. '    
  391. lp:
  392.        oldx = x
  393.        x = 2
  394.  
  395. '===== calculate cursor position
  396.      
  397.        FOR i = 0 TO s
  398.          x = x + LEN(sel$(i, 0))
  399.        NEXT
  400.  
  401. '===== fix cursor position to start of selection string
  402.      
  403.        x = x - LEN(sel$(i - 1, 0))
  404.    
  405.  
  406. '===== put OLD selection back to original color 
  407.  
  408.        COLOR fgc, bgc
  409.        LOCATE 2, oldx
  410.        PRINT sel$(olds, 0);
  411.    
  412. '===== select NEW selection with highlite color
  413.    
  414.        COLOR 15, fgc
  415.        LOCATE 2, x
  416.        PRINT sel$(s, 0);
  417.    
  418.  
  419. '===== print sel$(s,10) 'message string' on line 25
  420.  
  421.        t = INT((80 - LEN(sel$(s, 10))) / 2)
  422.        IF t * 2 + LEN(sel$(s, 10)) < 78 THEN f$ = STRING$((78 - (t * 2 + LEN(sel$(s, 10)))), "─") ELSE f$ = ""
  423.        LOCATE 25, 1
  424.        COLOR bgc, fgc
  425.        PRINT SPACE$(t) + sel$(s, 10) + f$ + SPACE$(t);
  426.        COLOR fgc, bgc
  427.  
  428. '
  429. '===== wait for key to be pressed
  430.  
  431. get.key:
  432.        DO
  433.          a$ = INKEY$
  434.        LOOP WHILE a$ = ""
  435.  
  436. '
  437. '===== if the key is an extended key ( len > 1 ) then process ext keys
  438.  
  439.        IF LEN(a$) > 1 THEN GOTO get.curkey
  440.       
  441. '===== else make the key Upper Case   
  442.       
  443.        a$ = UCASE$(a$)
  444.  
  445. '===== check for escape key  
  446. '===== if esc then return with sel=-1
  447.  
  448.        IF a$ = CHR$(27) THEN sel = -1: EXIT SUB
  449. '   
  450. '===== if key is CR then return with selection number in sel   
  451. '   
  452. ret:   IF a$ <> CHR$(13) GOTO test.num
  453.       
  454.        sel = (s * 10) + subnum: EXIT SUB
  455.                                      
  456.  
  457. '===== test for number key
  458. test.num:
  459.        q = VAL(a$)
  460.        IF q >= 1 AND q <= cv AND q <= 9 AND q > 0 THEN
  461.        subsel = q
  462.        GOSUB update.sub
  463.        a$ = CHR$(13): GOTO ret
  464.        END IF
  465.       
  466.  
  467. '====== test for first letter key
  468.      
  469. '===== if c<>0 then add 1 to c and test for match  
  470. '===== this allows multilble selections with the same letter  
  471. '===== round-robin type  
  472. '    
  473. test.ltr:
  474.        IF c <> 0 THEN
  475.          c = c + 1
  476.          c = INSTR(c, s$, a$)
  477.          IF c <> 0 GOTO tr
  478.        END IF
  479.        c = INSTR(s$, a$)
  480.        IF c = 0 GOTO get.key
  481. tr:    olds = s
  482.        s = c - 1
  483.        subsel = 1
  484.        subnum = 1
  485.        GOSUB dis.sub
  486.        GOTO lp
  487.  
  488.  
  489.  
  490. '===== check for cursor keys
  491.  
  492. get.curkey:                       
  493.    
  494.     a = ASC(RIGHT$(a$, 1))
  495.     IF a <> 77 AND a <> 75 AND a <> 72 AND a <> 80 GOTO get.key
  496.     olds = s
  497.     IF a <> 77 AND a <> 75 GOTO get.updnkey
  498.    
  499.     
  500.     IF a = 77 THEN s = s + 1
  501.     IF a = 75 THEN s = s - 1
  502.     IF s > sel THEN s = 0
  503.     IF s < 0 THEN s = sel
  504.     c = s
  505.     subsel = 1
  506.     subnum = 1
  507.    
  508.     GOSUB dis.sub
  509.     GOTO lp
  510.  
  511.  
  512. get.updnkey:
  513.  
  514.          IF a = 80 THEN subsel = subsel + 1
  515.          IF a = 72 THEN subsel = subsel - 1
  516.          GOSUB update.sub
  517.          GOTO lp
  518.  
  519.  
  520. '
  521. '===== display the sub menu box
  522. '
  523. dis.sub:
  524.         
  525.          i = 0
  526.          a = 0
  527.          xtemp = x
  528.       
  529. '===== clear old box 
  530.          COLOR fgc, bgc
  531.          FOR i = 1 TO cv + 2
  532.              LOCATE 3 + i, zold - 1
  533.              PRINT STRING$(aold + 6, "░")
  534.          NEXT
  535.          
  536.       
  537. '===== get the length of the longest string
  538. '===== to be displayed
  539.       
  540.       
  541.        i = 0
  542.       
  543.        DO
  544.           i = i + 1
  545.           IF LEN(sel$(s, i)) > a THEN a = LEN(sel$(s, i))
  546.        LOOP WHILE sel$(s, i) <> "" AND i < 10
  547.       
  548.        cv = 0
  549.       
  550.        IF i = 1 THEN RETURN
  551.        aold = a
  552.        cvold = cv
  553.        cv = i - 1
  554.        cvold = cv
  555.  
  556. '===== calculate cursor position
  557.       
  558.        x = 2
  559.        FOR i = 0 TO s
  560.          x = x + LEN(sel$(i, 0))
  561.        NEXT
  562.  
  563. '===== fix cursor position to start of selection string
  564.     
  565.        x = x - LEN(sel$(i - 1, 0))
  566.  
  567.  
  568.  
  569. '===== if starting position + longest string found > 80 then adjust start pos.
  570. '===== if starting pos. < 2 then set it to 2.
  571.  
  572.        
  573.        IF x + a > 78 THEN z = 76 - a ELSE z = x - 5
  574.     
  575.        IF z < 2 THEN z = 2
  576.        zold = z
  577.        LOCATE 4, z - 1: PRINT "┌" + STRING$(x - z, "─");
  578.        LOCATE 4, x: PRINT "┘" + SPACE$(LEN(sel$(s, 0)) - 2) + "└";
  579.        b = x + LEN(sel$(s, 0)) - 1
  580.        n = z + a + 3
  581.        PRINT STRING$((n) - b, "─") + "┐";
  582.       
  583.        FOR i = 1 TO cv
  584.          LOCATE i + 4, z - 1: PRINT "│";
  585.          PRINT LTRIM$(STR$(i)) + ". " + sel$(s, i) + SPACE$(a - (LEN(sel$(s, i)) - 1)) + "│";
  586.        NEXT
  587.       
  588.        LOCATE i + 4, z - 1: PRINT "└" + STRING$(a + 4, "─") + "┘";
  589.        x = xtemp
  590.  
  591.  
  592. '===== display the selection in the sub menu
  593.  
  594. update.sub:
  595.       
  596.       
  597.        IF cv = 0 THEN RETURN
  598.        IF subsel > cv THEN subsel = 1
  599.        IF subsel < 1 THEN subsel = cv
  600.        LOCATE subnum + 4, z
  601.        PRINT LTRIM$(STR$(subnum)) + ". " + sel$(s, subnum);
  602.        LOCATE subsel + 4, z
  603.        COLOR 15, fgc
  604.        PRINT LTRIM$(STR$(subsel)) + ". " + sel$(s, subsel);
  605.        subnum = subsel
  606.  
  607.  
  608.        RETURN
  609.  
  610. END SUB
  611.  
  612.