home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP13.EXE / CHP1351.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  3.3 KB  |  121 lines

  1. /*
  2.    Listing 13.51  HowTo(), a user interface building block function.
  3.    Author: Craig Yellick
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. #command DEFAULT <a> to <b> => <a> := if(<a> = nil, <b>, <a>)
  14.  
  15. /*
  16.    This #define will cause the testing/demo routine to be included in
  17.    the compile. Delete the line and recompile to get rid of the test
  18.    code and produce a smaller OBJ file.  However-- leave the source
  19.    code here so you can more easily test changes and additions in the
  20.    future.
  21. */
  22. #define TESTING
  23.  
  24. #ifdef TESTING
  25.   function HowToTest()
  26.   local answer
  27.  
  28.     //  Clean up screen so this demo looks nice.
  29.     setcursor(0)
  30.     cls
  31.  
  32.     HowTo({"If you want to continue, select CONTINUE.", ;
  33.            "If you do not want to continue, select DON'T.", ;
  34.            "If you're not sure, select DON'T."}, .t.)
  35.  
  36.     @ 9, 11 to 12,22 double
  37.     @ 10,12 prompt " CONTINUE "
  38.     @ 11,12 prompt " DON'T    "
  39.     menu to answer
  40.  
  41.     HowTo("This is another set of instructions...")
  42.  
  43.     scroll(9, 11, 12, 22, 0)
  44.     @ 10,12 say "Press a key..."
  45.     inkey(0)
  46.  
  47.     HowTo()
  48.  
  49.     setcursor(1)
  50.     cls
  51.   return nil
  52.  
  53. #endif
  54.  
  55. /*------------------------------------------------------------------*/
  56.  
  57. function HowTo(msg_, hasHelp)
  58. /*
  59.    General-purpose "How To Do It" function, displays specified lines of
  60.    text at bottom of screen that describe what's happening on the screen
  61.    and what the user is expected to do next.
  62.  
  63.    Parameter  Description
  64.    ---------  -----------
  65.    msg_       Array of message lines. (If single line, a string is ok.)
  66.    hasHelp    Logical flag, .t. indicates a help screen is available.
  67.  
  68.    HowTo() called with no parameters removes the last set of messages
  69.    and resets the low row variable so future calls do not mess up the
  70.    screen.
  71. */
  72.  
  73. #define HELP_KEY_MSG  " [ F1-Help ]"
  74.  
  75. local i
  76.  
  77. //  Remember the lowest row number the previous messages occupied.
  78. static previous
  79.  
  80.   //  Clear previous message lines (if any).
  81.   if previous <> nil
  82.     scroll(previous, 0)
  83.   endif
  84.  
  85.   //  No message, reset
  86.   if msg_ = nil
  87.     previous := nil
  88.  
  89.   //  Displaying message lines.
  90.   else
  91.     //  As a convenience feature if there's only one line in the
  92.     //  message it can be passed as a single string instead of
  93.     //  and array.
  94.     if valtype(msg_) = "C"
  95.       msg_ := {msg_}
  96.     endif
  97.  
  98.  
  99.     //  Display lines to bottom of screen.
  100.     for i := 0 to (len(msg_) -1)
  101.       @ maxrow() - i, 0 say padr(msg_[ len(msg_) -i ], maxcol())
  102.     next i
  103.     @ row() -1, 0 say replicate(chr(196), maxcol())
  104.     previous := row()
  105.  
  106.     /*
  107.       Display message regarding the help key, if applicable. Clipper's
  108.       "short circuit logic" allows us to check for a valid type on the
  109.       same line as we need the actual value, it won't even consider
  110.       ".and. hasHelp" unless the valtype() function returns true.
  111.     */
  112.     if (valtype(hasHelp) = "L") .and. hasHelp
  113.       setpos(maxrow(), maxcol() -len(HELP_KEY_MSG))
  114.       dispout(HELP_KEY_MSG)
  115.     endif
  116.   endif
  117.  
  118. return nil
  119.  
  120. // end of file CHP1351.PRG
  121.