home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n13.zip / PROMPTYN.PRG < prev    next >
Text File  |  1991-06-10  |  6KB  |  197 lines

  1. PROCEDURE promptyn
  2. *
  3. PARAMETERS mess, choice_1, choice_2, top, left, win_title
  4. *
  5. * mess      = <exp_C>, message to display in the box
  6. * choice_1  = <exp_C>, first of the two choices
  7. * choice_2  = <exp_C>, second of the two choices
  8. * top       = <exp_N>, top row of the window
  9. * left      = <exp_N>, left column of the window
  10. * win_title = <exp_C>, appears on top bar of window
  11.  
  12. **************************
  13. * Local Memory Variables *
  14. **************************
  15. PRIVATE promptvar, ret_val
  16.  
  17. * Initialize the menu variable
  18. promptvar =1
  19.  
  20. * What we return to the calling .prg
  21. ret_val = SPACE(5)
  22.  
  23. **************************************************
  24. * Fill in some parameters if they weren't passed *
  25. **************************************************
  26. IF PARAMETERS() < 1 .OR. EMPTY(mess)
  27.    mess = "Please Choose:"
  28. ENDIF
  29.  
  30. IF PARAMETERS() < 3 .OR. (EMPTY(choice_1) .AND. EMPTY(choice_2))
  31.    choice_1 = "Yes"
  32.    choice_2 = "No"
  33. ENDIF
  34.  
  35. * Pad everything with spaces to make it look nicer
  36. choice_1 = " " + choice_1 + " "
  37. choice_2 = " " + choice_2 + " "
  38.  
  39. *********************************************
  40. * Calculate prompt window size and location *
  41. *********************************************
  42.  
  43. * Figure out our prompt window width
  44. winwidth = MIN(LEN(mess) + LEN(choice_1) + LEN(choice_2) + 5, ;
  45. SCOLS())
  46.  
  47. * Now the location, more parameters if necessary
  48. IF PARAMETERS() < 4
  49.    top = 99                          && Set to 99 if top is not specified
  50. ENDIF
  51.  
  52. * If top not specified _or_ passed 99
  53. IF top = 99
  54.    top = INT((SROWS()/2)-2)          && calculate center based on screen rows
  55. ENDIF
  56. bottom = top + 4
  57.  
  58. * If left not specified _or_ passed 99
  59. IF PARAMETERS() < 5
  60.    left = 99                         && Set to 99 if left is not specified
  61. ENDIF
  62.  
  63. IF left = 99
  64.    left = INT((SCOLS()-winwidth)/2)  && calc center based on screen columns
  65. ENDIF
  66.  
  67. right = left + winwidth
  68.  
  69. **********************************
  70. * Define and activate the window *
  71. **********************************
  72. IF PARAMETERS() < 6
  73.    DEFINE WINDOW promptwin FROM top,left TO top+4,right PANEL
  74. ELSE
  75.    DEFINE WINDOW promptwin FROM top,left TO top+4,right PANEL ;
  76.    TITLE " " + win_title + " "
  77. ENDIF
  78. ACTIVATE WINDOW promptwin
  79.  
  80. *********************************
  81. * Put the choices on the screen *
  82. *********************************
  83. @WROW()-2,1 SAY mess
  84. @ROW(),COL()+1 PROMPT choice_1 MESSAGE " "
  85. @ROW(),COL()+1 PROMPT choice_2 MESSAGE " "
  86. MENU TO promptvar
  87.  
  88. ***************************
  89. * Clean house and go home *
  90. ***************************
  91. RELEASE WINDOW promptwin
  92.  
  93. IF EMPTY(promptvar)            && They pressed <escape>
  94.    ret_val = ""
  95. ELSE
  96.    ret_val = IIF(promptvar=1,ALLTRIM(choice_1),ALLTRIM(choice_2))
  97. ENDIF
  98.  
  99. RETURN ret_val
  100. * eof
  101. FUNCTION promptyn
  102. PARAMETERS mess, choice_1, choice_2, top, left, win_title
  103. *
  104. * mess      = <exp_C>, message to display in the box
  105. * choice_1  = <exp_C>, first of the two choices
  106. * choice_2  = <exp_C>, second of the two choices
  107. * top       = <exp_N>, top row of the window
  108. * left      = <exp_N>, left column of the window
  109. * win_title = <exp_C>, appears on top bar of window
  110.  
  111. **************************
  112. * Local Memory Variables *
  113. **************************
  114. PRIVATE promptvar, ret_val
  115.  
  116. * Initialize the menu variable
  117. promptvar =1
  118.  
  119. * What we return to the calling .prg
  120. ret_val = SPACE(5)
  121.  
  122. **************************************************
  123. * Fill in some parameters if they weren't passed *
  124. **************************************************
  125. IF PARAMETERS() < 1 .OR. EMPTY(mess)
  126.    mess = "Please Choose:"
  127. ENDIF
  128.  
  129. IF PARAMETERS() < 3 .OR. (EMPTY(choice_1) .AND. EMPTY(choice_2))
  130.    choice_1 = "Yes"
  131.    choice_2 = "No"
  132. ENDIF
  133.  
  134. * Pad everything with spaces to make it look nicer
  135. choice_1 = " " + choice_1 + " "
  136. choice_2 = " " + choice_2 + " "
  137.  
  138. *********************************************
  139. * Calculate prompt window size and location *
  140. *********************************************
  141. * Figure out our prompt window width
  142. winwidth = MIN(LEN(mess) + LEN(choice_1) + LEN(choice_2) + 5, ;
  143. SCOLS())
  144.  
  145. * Now the location, more parameters if necessary
  146. IF PARAMETERS() < 4
  147.    top = 99                  && Set to 99 if top is not specified
  148. ENDIF
  149.  
  150. * If top not specified _or_ passed 99
  151. IF top = 99
  152.    top = INT((SROWS()/2)-2)  && calculate center based on screen rows
  153. ENDIF
  154. bottom = top + 4
  155.  
  156. * If left not specified _or_ passed 99
  157. IF PARAMETERS() < 5
  158.    left = 99                 && Set to 99 if left is not specified
  159. ENDIF
  160.  
  161. IF left = 99                 && calc center based on screen columns
  162.    left = INT((SCOLS()-winwidth)/2)
  163. ENDIF
  164.  
  165. right = left + winwidth
  166.  
  167. **********************************
  168. * Define and activate the window *
  169. **********************************
  170. IF PARAMETERS() < 6
  171.    DEFINE WINDOW promptwin FROM top,left TO top+4,right PANEL
  172. ELSE
  173.    DEFINE WINDOW promptwin FROM top,left TO top+4,right PANEL ;
  174.    TITLE " " + win_title + " "
  175. ENDIF
  176. ACTIVATE WINDOW promptwin
  177.  
  178. *********************************
  179. * Put the choices on the screen *
  180. *********************************
  181. @WROW()-2,1 SAY mess
  182. @ROW(),COL()+1 PROMPT choice_1 MESSAGE " "
  183. @ROW(),COL()+1 PROMPT choice_2 MESSAGE " "
  184. MENU TO promptvar
  185.  
  186. ***************************
  187. * Clean house and go home *
  188. ***************************
  189. RELEASE WINDOW promptwin
  190. IF EMPTY(promptvar)            && They pressed <escape>
  191.    ret_val = ""
  192. ELSE
  193.    ret_val = IIF(promptvar=1,ALLTRIM(choice_1),ALLTRIM(choice_2))
  194. ENDIF
  195. RETURN ret_val
  196. * eof
  197.