home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / Basic / QMENU7.ZIP / MENUWIND.BAS next >
Encoding:
BASIC Source File  |  1990-06-16  |  15.4 KB  |  521 lines

  1. '   MENUFUN Written by: Robert R. Smith
  2. '                       3812 Red Bud
  3. '                       Imperial, MO  63052-1161
  4. '                       CIS 72447,2643
  5. '
  6. '
  7. '     Memory Moves with QB  by David Cleary
  8. '     The QBNews  Volume  1, Number  1   November  1, 1989
  9. '
  10. '  I down loaded both from GENIE in MICROSOFT Libary
  11. '
  12. '   screen save and restore changed by me to use QBX STRINGASSIGN
  13. '   changed to popup menuwindow with screen save and restore
  14. '
  15. '   MENUWIND By:        Raymond E Dixon
  16. '                       5815 Buckley Dr.
  17. '                       Jacksonville, Fl. 32244
  18. '
  19. '                       (904) 778-4048
  20. '                       (904) 772-0329
  21. '
  22. '           Microsoft BASIC 7.0, Professional Development System
  23. '              Copyright (C) 1987-1989, Microsoft Corporation
  24. '
  25. '           Microsoft QBX 7.0, Professional Development System
  26. '              Copyright (C) 1987-1989, Microsoft Corporation
  27. '
  28. '    I would like to thank Microsoft for a great Program and
  29. '    anyone serious about basic should consider (PDS) it,s
  30. '    worth the upgrade.
  31. '
  32. '      I think the only routine that won't work with QB45 is
  33. '      STRINGASSIGN  (load QBX with /l to load QBX.QLB)
  34. '      which is a QBX function , replace with ALIAS "B$ASSN" for QB45.
  35. '      these routines will work with QBX or BC command line.
  36. '        (remember STRINGASSIGN is a memory move)
  37. '
  38. '      Buffer(1 to 2000) = 4000 bytes for screen'  2 bytes per integer
  39. '      buffer = 8000 = 4 screens etc.
  40. '      screens saved can be restored as many times as nessary
  41. '      see subs scrnsave and restore for use of stringassign
  42. '
  43. '     CALL STRINGASSIGN(FromSeg, FromOfs, NumBytes, ToSeg, ToOfs, NumBytes)
  44. '
  45. '      with all the window programs around why write this, simple I write
  46. '      small programs and need menus and windows with out loading
  47. '      hundreds of routines I don't need and save thousands of bytes.
  48. '      besides it's fun and I learn a lot from the exercize.
  49. '
  50. '      I remember the days when basic was fun and free now everybody
  51. '      want's to make a buck, lets see some free code out there.
  52. '
  53. '
  54. DECLARE SUB SCRREST (Buffer%(), ScnNo%)
  55. DECLARE SUB SCRSAVE (Buffer%(), ScnNo%)
  56. DECLARE SUB MenuArray (I%, length%, MenuStr$, Delimiters$, option$())
  57. DECLARE SUB sglbox (leftcol%, toprow%, endcol%, endrow%)
  58. DECLARE FUNCTION MenuWindow% (row%, col%, MenuStr$, Title$, MenuFore%, MenuBack%, Reversed%)
  59. DECLARE FUNCTION str2token$ (Srce$, DELIM$)
  60. DECLARE SUB dblbox (Title$, leftcol%, toprow%, endcol%, endrow%)
  61. DECLARE SUB WaitKey ()
  62.  
  63. DEFINT A-Z
  64.  
  65. 'Define Constants
  66.  
  67. CONST True = 1
  68. CONST False = NOT True
  69.  
  70. CONST Black = 0
  71. CONST Blue = 1
  72. CONST Green = 2
  73. CONST Cyan = 3
  74. CONST Red = 4
  75. CONST Magenta = 5
  76. CONST Brown = 6
  77. CONST White = 7
  78. CONST Bright = 8
  79. CONST Blink = 16
  80. CONST Yellow = Brown + Bright
  81.  
  82. 'Define Data Types
  83.  
  84. TYPE MenuData
  85.    WordStart  AS INTEGER
  86.    WordLen    AS INTEGER
  87.    MenuLetter AS STRING * 1
  88.    MenuWord   AS STRING * 40
  89. END TYPE
  90.  
  91. 'Declare Functions
  92.  
  93.    'menu option
  94.  
  95.    DIM option$(20)
  96.  
  97. 'buffer for holding 2 screens , 4000 * 2 bytes for Integer = 8000 bytes total
  98.  
  99.    DIM Buffer(1 TO 4000)  '2000 integers = 4000 bytes for screen
  100.  
  101. KEY OFF
  102. COLOR White, Blue
  103. CLS
  104.  
  105. 'Main loop
  106.  
  107. FOR I = 1 TO 25
  108. LOCATE I, 1
  109. PRINT STRING$(80, 176);
  110. NEXT
  111.      a$ = " Menu Windows By: Raymond E Dixon "
  112.   LOCATE 5, (80 - LEN(a$)) / 2
  113.   PRINT a$;
  114.      a$ = " 5815 Buckley Dr. Jacksonville, Fl 32244 "
  115.   LOCATE 23, (80 - LEN(a$)) / 2
  116.   PRINT a$;
  117.  
  118. leftcol = 1: toprow = 1: endcol = 80: endrow = 25
  119. CALL sglbox(leftcol, toprow, endcol, endrow)
  120.  
  121.  
  122. DO
  123.  
  124.    LOCATE , , 0
  125.  
  126.            'menu$ maybe one string seperated by a , for each selection
  127.  
  128.            menu$ = "A - Select Type,"
  129.    menu$ = menu$ + "B - Update - Search Parts,"
  130.    menu$ = menu$ + "C - Print Parts List,"
  131.    menu$ = menu$ + "D - Color,"
  132.    menu$ = menu$ + "E - Exit to Dos"
  133.  
  134.    Title$ = "Main Menu" ' title$ maybe null ""
  135.  
  136.      'if row or column <= 1 then menu is centered on screen
  137.      'if col is to large to fit then is adjusted
  138.      'if row is to large to fit then is adjusted
  139.  
  140.    menuitem = MenuWindow%(0, 0, menu$, Title$, Black, White, Red)' + Bright)
  141.  
  142.    'a case for each menu item
  143.    SELECT CASE menuitem
  144.       CASE 1 'menu item 1
  145.  
  146.          Title$ = "Select Menu"
  147.          menu$ = "Color/TV,BW/TV,STEREO,VCR,PROJECTION/TV"
  148.          menuitem = MenuWindow%(0, 50, menu$, Title$, Black, White, Red)' + Bright)
  149.          
  150.          a$ = "You selected " + option$(menuitem)
  151.          LOCATE 18, (80 - LEN(a$)) / 2
  152.          PRINT a$;
  153.  
  154.          WaitKey
  155.  
  156.       CASE 2  'menu item
  157.          
  158.          a$ = "You selected " + option$(menuitem)
  159.          LOCATE 18, (80 - LEN(a$)) / 2
  160.          PRINT a$;
  161.          
  162.          WaitKey
  163.          
  164.       CASE 3  'menu item
  165.  
  166.          a$ = "You selected " + option$(menuitem)
  167.          LOCATE 18, (80 - LEN(a$)) / 2
  168.          PRINT a$;
  169.          
  170.          WaitKey
  171.          
  172.       CASE 4  'menu item
  173.          
  174.          a$ = "You selected " + option$(menuitem)
  175.          LOCATE 18, (80 - LEN(a$)) / 2
  176.          PRINT a$;
  177.  
  178.          WaitKey
  179.          
  180.       CASE ELSE   'Exit loop
  181.          QuitFlag% = True
  182.  
  183.    END SELECT
  184.    CALL SCRREST(Buffer(), 1)
  185.  
  186. LOOP UNTIL QuitFlag%
  187.  
  188. 'Terminate Program
  189.  
  190. COLOR White, Blue
  191. CLS
  192.    
  193. END
  194.  
  195. '
  196.   SUB dblbox (Title$, leftcol, toprow, endcol, endrow)
  197. ' call routine
  198. '    leftcol = 1: toprow = 1: endcol = 80: endrow = 23
  199. '    leftcol = 1: toprow = 1: endcol = 80: endrow = 23
  200.  
  201. '    call dblbox(title$,leftcol,toprow,endcol,endrow)
  202. 'Qdblbox
  203.       LOCATE toprow, leftcol
  204. 'draw drawpos of box
  205.       PRINT CHR$(201);
  206.  
  207.       FOR drawpos = (leftcol + 1) TO (endcol - 1)
  208.          PRINT CHR$(205);
  209.       NEXT drawpos
  210.  
  211.       PRINT CHR$(187)
  212. 'draw side of box
  213.       FOR drawpos = (toprow + 1) TO (endrow - 1)
  214.          LOCATE drawpos, leftcol
  215.          PRINT CHR$(186);
  216.          LOCATE drawpos, endcol
  217.          PRINT CHR$(186);
  218.       NEXT drawpos
  219. 'draw bottom of box
  220.       LOCATE endrow, leftcol
  221.       PRINT CHR$(200);
  222.       FOR drawpos = (leftcol + 1) TO (endcol - 1)
  223.          PRINT CHR$(205);
  224.       NEXT drawpos
  225.  
  226.       PRINT CHR$(188);
  227.  
  228.             tx$ = RTRIM$(Title$)
  229.             IF LEN(tx$) > 0 THEN
  230.                 
  231.                 length = endcol - leftcol
  232.                 IF (LEN(tx$) + 2) < length THEN
  233.                     LOCATE toprow, leftcol + INT(length / 2 - LEN(tx$) / 2) - 1
  234.                     PRINT " "; tx$; " ";
  235.                 ELSE
  236.                     LOCATE toprow - 1, leftcol
  237.                     PRINT LEFT$(" " + tx$ + " ", (endcol - leftcol + 1))
  238.                 END IF
  239.                 
  240.             END IF
  241.  
  242.    END SUB
  243.  
  244. SUB MenuArray (I, length, MenuStr$, Delimiters$, option$())
  245.  
  246. ' Invoke str2token$ with the string to tokenize.
  247.  
  248. Array$ = str2token$(MenuStr$, Delimiters$)
  249.  I = 0
  250. length = 0
  251.  
  252. DO
  253.    I = I + 1
  254.    option$(I) = Array$
  255.  
  256.    'get max option length for display
  257.  
  258.    IF LEN(option$(I)) > length THEN
  259.    length = LEN(option$(I))
  260.    END IF
  261.  
  262.    ' Call str2token$ with a null string so it knows this
  263.    ' isn't the first call.
  264.  
  265.    Array$ = str2token$("", Delimiters$)
  266.  
  267. LOOP WHILE Array$ <> ""
  268.  
  269.  
  270. END SUB
  271.  
  272. '
  273. '    menuwindow saves and restores screen
  274. '
  275. ' Title$ = "Title"  maybe null ""
  276. ' Menu$ = "A-menu1,B-menu2,3-menu3,Menu4"
  277. '          first letter must be different and Caps or Num
  278. '
  279. '     if row  <= 1 then menu is centered on screen vert
  280. '     if column <= 1 then menu is centered on screen horiz
  281. '     if col is to large to fit then is adjusted
  282. '     if row is to large to fit then is adjusted
  283. '     if row and col = 0 then menu is centered on screen
  284. '
  285. '
  286. FUNCTION MenuWindow% (row%, col%, MenuStr$, Title$, MenuFore%, MenuBack%, Reversed%)
  287.    SHARED Buffer()
  288.    col% = col% + 1
  289.    DIM Selection(1 TO 20) AS MenuData   '20 assumed to be the maximum selections
  290.    COLOR MenuFore%, MenuBack%
  291.    SHARED option$()
  292.  
  293.    CALL SCRSAVE(Buffer(), 1)
  294. ' Set up the menuitems.
  295.  
  296.     CALL MenuArray(I, length, MenuStr$, ",", option$())
  297.  
  298.     MenuChar% = 0
  299.  
  300.     'adjust col to fit
  301.     IF col% > 80 - length THEN
  302.     col% = (80 - length)
  303.     END IF
  304.     'adjust row to fit
  305.     IF row% > 23 - I THEN
  306.     row% = (24 - I)
  307.     END IF
  308.  
  309.     'if column <= 1 then window is centered
  310.     IF col% <= 1 THEN
  311.     col% = (80 - length) / 2
  312.     END IF
  313.     'if row  <= 1 then window is centered
  314.     IF row% <= 1 THEN
  315.     row% = (24 - I) / 2
  316.     END IF
  317.  
  318.     FOR j = 1 TO I
  319.  
  320.     LOCATE row% + j, col%
  321.     PRINT option$(j) + STRING$(length - LEN(option$(j)), " ");
  322.     NEXT j
  323.  
  324.      leftcol = col% - 1: toprow = row%: endcol = col% + length: endrow = row% + j
  325.  
  326.       LOCATE toprow, leftcol
  327. 'draw drawpos of box
  328.       PRINT CHR$(201) + STRING$(endcol - leftcol - 1, 205) + CHR$(187);
  329. 'draw side of box
  330.  
  331.       FOR drawpos = (toprow + 1) TO (endrow - 1)
  332.          LOCATE drawpos, leftcol
  333.          PRINT CHR$(186);
  334.          LOCATE drawpos, endcol
  335.          PRINT CHR$(186);
  336.       NEXT drawpos
  337.  
  338. 'draw bottom of box
  339.  
  340.       LOCATE endrow, leftcol
  341.       PRINT CHR$(200) + STRING$(endcol - leftcol - 1, 205) + CHR$(188);
  342.  
  343.             tx$ = RTRIM$(Title$)
  344.             IF LEN(tx$) > 0 THEN
  345.  
  346.                 lgth = endcol - leftcol
  347.                 IF (LEN(tx$) + 2) < lgth THEN
  348.                     LOCATE toprow, leftcol + INT(lgth / 2 - LEN(tx$) / 2)
  349.                     PRINT "["; tx$; "]";
  350.                 ELSE
  351.                     LOCATE toprow - 1, leftcol - 1
  352.                     PRINT LEFT$("|" + tx$ + "|", (endcol - leftcol + 3))
  353.                 END IF
  354.  
  355.             END IF
  356.  
  357.    FOR MenuChar% = row% + 1 TO row% + I'  Starts loop to test characters in menu
  358.       Test% = SCREEN(MenuChar%, col%)
  359.  
  360.       SELECT CASE Test%
  361.         CASE 64 TO 91, 47 TO 58  'Test to see if Character is between A and Z
  362.          MenuNum = MenuNum + 1
  363.          Selection(MenuNum).WordStart% = MenuChar%                       'Sets first column position in table for MenuWord and MenuLetter
  364.          Selection(MenuNum).MenuLetter = CHR$(Test%)                     'Sets the letter to use for menu selection
  365.          Selection(MenuNum).MenuWord = CHR$(Test%)                       'Puts whole word in table
  366.          Selection(MenuNum).WordLen% = 1                                 'gives the selection a starting lenth of one
  367.          CharString$ = CHR$(Test%)                                       'Sets first character of Character string
  368.  
  369.          'If not a space then add to Character string
  370.  
  371.         CASE IS <> 32
  372.          CharString$ = CharString$ + CHR$(Test%)                         'adds to string
  373.          Selection(MenuNum).MenuWord = CharString$                       'puts string in table
  374.          Selection(MenuNum).WordLen% = Selection(MenuNum).WordLen% + 1   'adjust word length in table
  375.       END SELECT
  376.       
  377.    NEXT MenuChar%
  378.    MenuNum = 1
  379.    DO
  380.       COLOR , MenuBack%
  381.       FOR MenuChar% = 1 TO 20                            '
  382.  
  383.       IF Selection(MenuChar%).WordStart% > 0 THEN
  384.       
  385.             COLOR Reversed%                              '
  386.             LOCATE Selection(MenuChar%).WordStart, col%
  387.                                                          'Runs through table to highlight
  388.             PRINT Selection(MenuChar%).MenuLetter;        'first Capital letter of each
  389.             LastSelection% = MenuChar%                   'menu selection
  390.          ELSE                                            '
  391.             MenuChar% = 20                               '
  392.          END IF                                          '
  393.       NEXT MenuChar%                                     '
  394.  
  395.       LOCATE Selection(MenuNum).WordStart, col%
  396.       COLOR White + Bright, Reversed%                    'Bright white will always be Highlighted foreground
  397.  
  398.       'Print selection in highlight colors
  399.       PRINT RTRIM$(option$(MenuNum)) + STRING$(length - LEN(option$(MenuNum)), " ");
  400.  
  401.       DO
  402.          Response$ = UCASE$(INKEY$)                      'Get key response
  403.          SELECT CASE Response$
  404.             CASE CHR$(0) + CHR$(72)                      'Left Cursor
  405.                GOSUB ResetSelection
  406.                MenuNum = MenuNum - 1                     'Decrement 1 in menu
  407.                IF MenuNum < 1 THEN
  408.                   MenuNum = LastSelection%
  409.                END IF
  410.             CASE CHR$(0) + CHR$(80)                      'Right Cursor
  411.                GOSUB ResetSelection
  412.                MenuNum = MenuNum + 1                     'Increment 1 in menu
  413.                IF MenuNum > LastSelection% THEN
  414.                   MenuNum = 1
  415.                END IF
  416.             CASE CHR$(13)                                'Carriage Return - Make selection
  417.                MenuWindow% = MenuNum
  418.             CASE "A" TO "Z", "0" TO "9"                             'Capital Letter - Speed Selection
  419.                FOR Compare% = 1 TO 20
  420.                   IF Response$ = Selection(Compare%).MenuLetter THEN
  421.                      MenuNum = Compare%
  422.                      MenuWindow% = MenuNum
  423.                      Response$ = CHR$(13)
  424.                   END IF
  425.                NEXT Compare%
  426.             CASE ELSE
  427.                'Fall through case                        'Anything else - forget it
  428.          END SELECT
  429.       LOOP UNTIL Response$ <> ""
  430.    LOOP UNTIL Response$ = CHR$(13)                       'Exit loop if Carriage Return
  431.    
  432.    CALL SCRREST(Buffer(), 1)
  433.  
  434.    EXIT FUNCTION
  435.  
  436. ResetSelection:         
  437.    LOCATE row%, col%                               'This subroutine resets
  438.    COLOR MenuFore%, MenuBack%                      'the current highlighted
  439.  
  440.    LOCATE Selection(MenuNum).WordStart, col%       'selection of the menubar to it's original color,
  441.    PRINT RTRIM$(option$(MenuNum)) + STRING$(length - LEN(option$(MenuNum)), " ");
  442.  
  443.    COLOR Reversed%
  444.  
  445.    LOCATE Selection(MenuNum).WordStart, col%
  446.    PRINT Selection(MenuNum).MenuLetter;
  447.  
  448.    RETURN
  449.    
  450. END FUNCTION
  451.  
  452. '
  453. '    leftcol = 1: toprow = 1: endcol = 80: endrow = 23
  454. '
  455. SUB sglbox (leftcol, toprow, endcol, endrow)
  456.       LOCATE toprow, leftcol
  457. 'top
  458.       PRINT CHR$(218);
  459.       FOR I = (leftcol + 1) TO (endcol - 1)
  460.          PRINT CHR$(196);
  461.       NEXT I
  462.       PRINT CHR$(191)
  463. 'sides
  464.       FOR I = (toprow + 1) TO (endrow - 1)
  465.          LOCATE I, leftcol
  466.          PRINT CHR$(179);
  467.          LOCATE I, endcol
  468.          PRINT CHR$(179);
  469.       NEXT I
  470. 'bottom
  471.       LOCATE endrow, leftcol
  472.       PRINT CHR$(192);
  473.       FOR I = (leftcol + 1) TO (endcol - 1)
  474.          PRINT CHR$(196);
  475.       NEXT I
  476.       PRINT CHR$(217);
  477.    END SUB
  478.  
  479. DEFSNG A-Z
  480. FUNCTION str2token$ (Srce$, DELIM$)
  481. STATIC Start%, SaveStr$
  482.  
  483.  
  484.    ' If first call, make a copy of the string.
  485.    IF Srce$ <> "" THEN
  486.       Start% = 1: SaveStr$ = Srce$
  487.    END IF
  488.  
  489.    BegPos% = Start%: Ln% = LEN(SaveStr$)
  490.    ' Look for start of a token (character that isn't delimiter).
  491.    WHILE BegPos% <= Ln% AND INSTR(DELIM$, MID$(SaveStr$, BegPos%, 1)) <> 0
  492.       BegPos% = BegPos% + 1
  493.    WEND
  494.    ' Test for token start found.
  495.    IF BegPos% > Ln% THEN
  496.       str2token$ = "": EXIT FUNCTION
  497.    END IF
  498.    ' Find the end of the token.
  499.    EndPos% = BegPos%
  500.    WHILE EndPos% <= Ln% AND INSTR(DELIM$, MID$(SaveStr$, EndPos%, 1)) = 0
  501.       EndPos% = EndPos% + 1
  502.    WEND
  503.    str2token$ = MID$(SaveStr$, BegPos%, EndPos% - BegPos%)
  504.    ' Set starting point for search for next token.
  505.    Start% = EndPos%
  506.  
  507. END FUNCTION
  508.  
  509. SUB WaitKey
  510.  
  511.    a$ = "Press any key to continue"
  512.          LOCATE 19, (80 - LEN(a$)) / 2
  513.          PRINT a$;
  514.    
  515.    DO
  516.       Key$ = INKEY$
  517.    LOOP UNTIL Key$ <> ""
  518.  
  519. END SUB
  520.  
  521.