home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / homonlib.zip / GENMEN.BAS < prev    next >
BASIC Source File  |  1995-04-13  |  6KB  |  159 lines

  1. DEFINT A-Z
  2.  
  3. ' $INCLUDE: 'PARM.INC'
  4. ' $INCLUDE: 'SETCURS.INC'
  5. ' $INCLUDE: 'TRUEFALS.INC'
  6.  
  7. DECLARE FUNCTION GenMen (choice$(), ok(), parm())
  8. DECLARE FUNCTION GenMen2 (choice$(), parm())
  9.  
  10. 'External procedures:
  11.  
  12. DECLARE SUB Center (row, text$)
  13. DECLARE FUNCTION GetKey$ (parm())
  14. DECLARE FUNCTION Istr$ (i)
  15.  
  16. FUNCTION GenMen (choice$(), ok(), parm())
  17. '****************************************************************************
  18. 'GenMen() is a general vertical lightbar menu function.  It will return the
  19. ' element number of the selected item or zero if the user presses ESC.
  20. '
  21. 'The ok() array is used to specify which choices are available:
  22. '
  23. '                      0=Not available  Non-zero=Ok
  24. '
  25. 'The ok() array must have subscripts equal to those of choice$() or those
  26. ' specified by parm(6 and 7) - See below.
  27. '
  28. '    parm(1)  =  top row
  29. '    parm(2)  =  left column  0=Center
  30. '    parm(3)  =  # blank lines between choices  >=0
  31. '    parm(4)  =  allow number keys if < 10 choices?  0=No  Non-zero=Yes
  32. '    parm(5)  =  initial selected choice
  33. '    parm(6)  =  minimum choice$() subscript  0=Use actual minimum (LBOUND)
  34. '    parm(7)  =  maximum choice$() subscript  0=Use actual maximum (UBOUND)
  35. '
  36. 'If a combination of any of the above parameters cause one or more menu items
  37. ' to be placed outside the actual screen area, a run-time error will occur.
  38. '
  39. 'parm(4) indicates whether the user can press a number key (1-9) to select an
  40. ' option when there are 9 or less choices.  Identifying the choices by number
  41. ' is the programmer's responsibility if this option is desired.  Note: this
  42. ' option can only be selected when all the choice$() subscripts are positive.
  43. '
  44. '    Example:  choice$(1) = " 1) Do this      "
  45. '              choice$(2) = " 2) Do that      "
  46. '              choice$(3) = " 3) Do the other "
  47. '
  48. 'parm(6 and 7) can specify minimum and maximum elements of the array to use
  49. ' if the actual array contains more elements than you want on the menu.
  50. '
  51. '    Example:  DIM choice$(-10 to 30)              This example would create
  52. '              (assign values to choice$()...)     a lightbar menu using only
  53. '              parm(6) = 1                         choices 1 through 5,
  54. '              parm(7) = 5                         ignoring any element below
  55. '              picked = GenMen(...)                1 or over 5.
  56. '
  57. 'Note: It is not recommended to include subscript zero in the choices sent to
  58. ' GenMen().  You will be unable to tell the difference between the user
  59. ' selecting element zero and the user pressing ESC.  Exception: When element
  60. ' zero is some sort of quit or exit option this might be acceptable.
  61. '
  62. '****************************************************************************
  63.  
  64. min = parm(6)                           'Determine minimum & maximum elements
  65. IF min = 0 THEN min = LBOUND(choice$)   'to use.
  66. max = parm(7)
  67. IF max = 0 THEN max = UBOUND(choice$)
  68.  
  69. numok = parm(4)                         'See if it's ok to use number keys.
  70. IF min < 0 THEN numok = FALSE           'This is only available when all
  71. IF numok THEN                           'elements are greater than zero and
  72.      sel = 0                            'there are nine or less choices.
  73.      FOR x = min TO max
  74.           sel = sel + 1
  75.           nums$ = nums$ + Istr$(x)      'Create a string of eligible numbers.
  76.      NEXT x
  77.      IF sel > 9 THEN numok = FALSE
  78. END IF
  79.  
  80. sel = parm(5)                           'Determine initial selection
  81. IF sel < min THEN sel = min
  82. IF sel > max THEN sel = max
  83.  
  84. oldcursor = SetCursor(SCNONE)           'Turn off the cursor
  85.  
  86. DO
  87.  
  88.      row = parm(1)                      'Show the menu options
  89.      FOR x = min TO max
  90.           IF ok(x) = 0 THEN COLOR parm(FGD)
  91.           IF x = sel THEN
  92.                COLOR parm(FGS), parm(BGS)
  93.                IF ok(x) = 0 THEN COLOR parm(FGDS)
  94.           END IF
  95.           IF parm(2) = 0 THEN
  96.                Center row, choice$(x)
  97.           ELSE
  98.                LOCATE row, parm(2): PRINT choice$(x);
  99.           END IF
  100.           COLOR parm(FGN), parm(BGN)
  101.           row = row + 1 + parm(3)
  102.      NEXT x
  103.  
  104.      k$ = GetKey$(parm())               'Get keyboard input
  105.      SELECT CASE k$
  106.           CASE CHR$(27)                                     'ESC
  107.                GenMen = 0
  108.                EXIT DO
  109.           CASE CHR$(13)                                     'Enter
  110.                IF ok(sel) THEN
  111.                     GenMen = sel
  112.                     EXIT DO
  113.                END IF
  114.           CASE CHR$(0) + CHR$(72)                           'Up arrow
  115.                sel = sel - 1
  116.           CASE CHR$(0) + CHR$(80)                           'Down arrow
  117.                sel = sel + 1
  118.           CASE ELSE                                         'Number key?
  119.                IF numok AND (INSTR(nums$, k$) > 0) THEN
  120.                     sel = VAL(k$)
  121.                     IF ok(sel) THEN
  122.                          GenMen = sel
  123.                          EXIT DO
  124.                     END IF
  125.                END IF
  126.      END SELECT
  127.  
  128.      IF sel < min THEN sel = max
  129.      IF sel > max THEN sel = min
  130.  
  131. LOOP
  132.  
  133. x = SetCursor(oldcursor)                'Restore the cursor
  134.  
  135. END FUNCTION
  136.  
  137. FUNCTION GenMen2 (choice$(), parm())
  138. '****************************************************************************
  139. 'GenMen2() is identical to GenMen() except that you need not pass the ok()
  140. ' array.  All elements default to available.
  141. '
  142. 'See GenMen() for more information.  The parm() settings are identical.
  143. '
  144. '****************************************************************************
  145.  
  146. min = LBOUND(choice$)
  147. max = UBOUND(choice$)
  148. REDIM ok(min TO max)                    'Create an ok() array and make all
  149. FOR x = min TO max                      'its elements non-zero.
  150.      ok(x) = TRUE
  151. NEXT x
  152.  
  153. GenMen2 = GenMen(choice$(), ok(), parm())
  154.  
  155. ERASE ok
  156.  
  157. END FUNCTION
  158.  
  159.