home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / winyn2.zip / WINYN2.PRG
Text File  |  1991-08-09  |  4KB  |  113 lines

  1. FUNCTION WinYN
  2. *-------------------------------------------------------------------------------
  3. *-- Programmer..: PC Magazine
  4. *-- Date........: 08/09/1991
  5. *-- Notes.......: This was supposedly gotten from PC Magazine by someone,
  6. *--               and entered into their machine. (Uploaded to AT-BBS). 
  7. *--               I don't know if they tested it. I made some minor changes, 
  8. *--               since I couldn't get it to work. It's purpose is to popup a 
  9. *--               window with two options for the user, returning a value ... 
  10. *--               it's not well designed, as it uses default color values and 
  11. *--               such. It appears to me that while it works, the folk at PC 
  12. *--               Rag could have spent just a bit more time on it ...
  13. *-- Written for.: dBASE IV, 1.1
  14. *-- Rev. History: 08/09/1991 -- modified to make the parameters function
  15. *--                             properly, to make it a bit more efficient,
  16. *--                             and for dUFLP standards -- Ken Mayer
  17. *-- Calls.......: None
  18. *-- Called by...: Any
  19. *-- Usage.......: WinYN("<cMess>","<cChoice1>","<cChoice2>",<nTop>,<nLeft>,;
  20. *--                     "<cTitle>")
  21. *-- Example.....: if WinYn("Choose:","Yes","No",10,12,"Is this ok?") = "Yes"
  22. *--                  do SOMETHING
  23. *--               endif
  24. *-- Returns.....: cChoice1 or cChoice2
  25. *-- Parameters..: cMess    = Message next to the two choices (may be left
  26. *--                             as a nul (""), in which case you get a
  27. *--                             default message)
  28. *--               cChoice1 = first of two choices (may be left nul, in which
  29. *--                             case the first choice is "Yes")
  30. *--               cChoice2 = second of two choices (may be left nul, in which
  31. *--                             case the second choice is "No")
  32. *--               nTop     = upper row of window -- may be sent as 0 or 99 to
  33. *--                             get default row (11)
  34. *--               nLeft    = left column of window -- no default.
  35. *--               cTitle   = Displayed in row 0 of window -- if nul, there
  36. *--                             will be nothing displayed in that row.
  37. *--------------------------------------------------------------------------
  38.  
  39. parameters cMess,cChoice1,cChoice2,nTop,nLeft,cTitle
  40.  
  41. cTalk = set("TALK")   && save this, so we can restore to original setting
  42. set talk off
  43.  
  44. if cMess = ""                         && set default if needed.
  45.     cMess = "Please Choose:"
  46. endif
  47.  
  48. if cChoice1 = "" .and. cChoice2 = ""  && set defaults if needed.
  49.     cChoice1 = "Yes"
  50.     cChoice2 = "No"
  51. endif
  52.  
  53. *-- pad choices and message with spaces
  54. cChoice1 = " &cChoice1 "
  55. cChoice2 = " &cChoice2 "
  56. cMess = " &cMess "
  57.  
  58. *-- set width of window
  59. nWinWidth = len(cMess)+len(cChoice1)+len(cChoice2)+5
  60.  
  61. *-- what if the width of the window is less than the width of
  62. *-- the TITLE? If that's the case, let's reset the width to the
  63. *-- width of the title (+2 spaces ... one on each side)
  64. if nWinWidth < len(cTitle)+2 
  65.     nWinWidth = len(cTitle)+2
  66. endif
  67.  
  68. *-- set top to default if necessary
  69. if nTop = 99 .or. nTop <= 0
  70.     nTop = 11
  71. endif
  72.  
  73. *-- make window five lines high ...
  74. nBottom = nTop + 5
  75.  
  76. *-- set right side of window ... (left column + window width ...)
  77. nRight = nLeft + nWinWidth
  78.  
  79. *-- define and activate window
  80. define window wWinNY from nTop,nLeft to nBottom,nRight panel
  81. activate window wWinNY
  82.  
  83. *-- define menu with two pads
  84. define menu mMen
  85. define pad pMen1 of mMen prompt cChoice1 at 2,len(cMess)+1
  86. define pad pMen2 of mMen prompt cChoice2 at 2,len(cMess)+len(cChoice1)+1
  87. on selection pad pMen1 of mMen deactivate menu
  88. on selection pad pMen2 of mMen deactivate menu
  89.  
  90. *-- if the title has anything in it, display it at row 0 (centering it)
  91. if cTitle <> " "
  92.     @0,(nWinWidth-len(cTitle))/2 say cTitle
  93. endif
  94.  
  95. *-- display the message
  96. @ 2,0 say cMess
  97.  
  98. *-- activate menu ...
  99. activate menu mMen
  100.  
  101. *-- Once a choice is made, deactivate the window ...
  102. deactivate window wWinNY
  103.  
  104. *-- reset Talk to it's previous status ...
  105. set talk &cTalk 
  106.  
  107. *-- return the trimmed value of the PROMPT (this is MUCH easier than was
  108. *-- previously designed, with a check to see which bar() was chosen, and
  109. *-- then trimming the CHOICE options, and all that ...)
  110. RETURN ltrim(trim(prompt()))
  111.  
  112. *-- EoF: WinYN()
  113.