home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / clipper / code_1.arc / TEM_UDFS.PRG < prev   
Text File  |  1989-01-02  |  51KB  |  1,023 lines

  1. * SYS_UDF.PRG
  2. * User Defined Functions by Gary L. Cota
  3. *     created: 11/25/88
  4. * last update: 01/01/89
  5. *
  6. ***************************************************************************
  7. *  To Whom It May Concern:                                                *
  8. *  ---------------------------------------------------------------------  * 
  9. *  The program code contained herein is a combination of User Defined     *
  10. *  Functions (UDFs) created by myself and functions collected from        *
  11. *  other various sources.  These sources include DATA BASED ADVISOR       *
  12. *  magazine, "PROGRAMMING IN CLIPPER" (first and second editions by       *
  13. *  Stephen Straley, D.O.S.S (Desk Of Stephen Straley newsletter, the      *
  14. *  REFERENCE(CLIPPER) newsletter to name  but a few.  I make no claim     *
  15. *  to ownership of these functions.  They are available your use but      *
  16. *  with no guarantee, warranty, or royalty involved from myself.          *
  17. *                                                                         *
  18. *  NOTE:  These functions were created for use with CLIPPER SUMMER '87    *
  19. *         Version only.  It is possible that some may work with the       *
  20. *         AUTUMN '86 Version but none have been tested with that ver-     *
  21. *         sion.                                                           *
  22. *                                                                         *
  23. *  NOTE:  The function names are prefixed with a "c_" to (hopefully)      *
  24. *         make them unique to current and future versions of CLIPPER      *
  25. *         and third party UDF libraries.                                  *
  26. *                                                                         * 
  27. *         All local variables are prefixed with a "_" (underscore) as     *
  28. *         in "_in_string".  Temporary work variables are prefixed and     *
  29. *         suffixed with an underscore as in _ma_, _mb_, _mc_, etc. to     *
  30. *         hopefully prevent any duplicate program memory variable         *
  31. *         names or CLIPPER reserved words.                                *
  32. *                                                                         *
  33. *                                            Gary L. Cota  11/25/88       *
  34. ***************************************************************************
  35. *
  36. *
  37. *
  38. FUNCTION c_ALLTRIM
  39.    ************************************************************************
  40.    *  PASS:     <expC1>                                                   *
  41.    *                                                                      *
  42.    *  RETURNS:  The character string minus trimmed leading and trailing   *
  43.    *            spaces.                                                   *
  44.    *                                                                      *
  45.    *  PURPOSE:  Uses less memory space than it's CLIPPER counterpart.     *
  46.    *                                                                      *
  47.    *  EXAMPLE:  mfirst = FIRST_NAME                                       *
  48.    *            mlast  = LAST_NAME                                        *
  49.    *            ? c_ALLTRIM(mfirst)+" "+c_ALLTRIM(mlast)                  *
  50.    ************************************************************************
  51.    *
  52.    PARAMETERS _in_string
  53.    *
  54. RETURN(LTRIM(TRIM(_in_string)))
  55. *
  56. *
  57. *
  58. FUNCTION c_BLANK
  59.    ************************************************************************
  60.    *  PASS:     <expC1>, <expC2> (optional)                               *
  61.    *                                                                      *
  62.    *  RETURNS:  The empty or blank value of a .DBF field.                 *
  63.    *                                                                      *
  64.    *  PURPOSE:  Initialize blank or empty memory variables from .DBF      *
  65.    *            fields.                                                   *
  66.    *                                                                      *
  67.    *  NOTES:    If second paramater is passed, logical fields will be     *
  68.    *            initialized to .F. (false).  If a second parameter is not *
  69.    *            passed, logical fields will be initialized to a character *
  70.    *            string of SPACE(1).                                       *
  71.    *                                                                      *
  72.    *            This function may be used in conjunction with the         *
  73.    *            c_DATAGONE() and c_MEMEMPTY() UDFs.                       *
  74.    *                                                                      *
  75.    *  EXAMPLE:  mCUSTOMER = c_BLANK(CUSTOMER)                             *
  76.    *            (where mCUSTOMER is a memory variable and CUSTOMER is a   *
  77.    *            .DBF field name.                                          *
  78.    *                                                                      *
  79.    *            MBILLABLE = c_BLANK(BILLABLE)                             *
  80.    *            (memory variable is initialized to " ")                   *
  81.    *                                                                      *
  82.    *            MBILLABLE = c_BLANK(BILLABLE,x)                           *
  83.    *            (memory variable is initialized to .F.)                   *
  84.    ************************************************************************
  85.    *
  86.    PARAMETERS _in_string, _my_
  87.    *
  88.    DO CASE
  89.       CASE TYPE("_in_string")="C"
  90.          * Character
  91.          RETURN(SPACE(LEN(_in_string)))
  92.          *
  93.       CASE TYPE("_in_string")="D"
  94.          * Date
  95.          RETURN(CTOD("  /  /  "))
  96.          *
  97.       CASE TYPE("_in_string")="L"
  98.          * Logical
  99.          IF PCOUNT() = 2
  100.             *****************************************************
  101.             * Second parameter passed.  Logical memory variable *
  102.             * will be initialized to .F..                       *
  103.             *****************************************************
  104.             RETURN(.F.)
  105.          ELSE
  106.             *****************************************************
  107.             * If one parameter passed, convert logical field to *
  108.             * character memory variable of SPACE(1).            *
  109.             *****************************************************
  110.             RETURN(SPACE(1))
  111.          ENDIF
  112.          *
  113.       CASE TYPE("_in_string")="M"
  114.          * Memo
  115.          RETURN(SPACE(512))
  116.          *
  117.       CASE TYPE("_in_string")="N"
  118.          * Numeric
  119.          RETURN(0.00)
  120.          *
  121.       OTHERWISE
  122.          RETURN(.F.)
  123.    ENDCASE
  124. RETURN(0)
  125. *
  126. *
  127. *
  128. FUNCTION c_BOXIT
  129.    ************************************************************************
  130.    *  PASS:     <expN1>, <expN2>, <expN3>, <expN4>, <expN5>, <expC1>      *
  131.    *                                                                      *
  132.    *            where:   <expN1> = top row                                *
  133.    *                     <expN2> = top column                             *
  134.    *                     <expN3> = bottom row                             *
  135.    *                     <expN4> = bottom column                          *
  136.    *                     <expN5> = box type 1-4 (1 is single line box, 2  *
  137.    *                               is double line box, 3 is double line   *
  138.    *                               top and bottom and single line sides,  *
  139.    *                               and 4 is single line top and bottom    *
  140.    *                               and double line sides).                *
  141.    *                     <expC1> = optional box color parameter           *
  142.    *                                                                      *
  143.    *  RETURNS:  Nothing                                                   *
  144.    *                                                                      *
  145.    *  PURPOSE:  Clears area and displays a box or window.                 *
  146.    *                                                                      *
  147.    *  EXAMPLE:  mboxtype  = 1            && single line box               *
  148.    *            mboxcolor = "+BG/N"      && color variable                *
  149.    *            *                                                         *
  150.    *             c_BOXIT(16,15,22,63,mtype,sys_box)                       *
  151.    *                                                                      *
  152.    ************************************************************************
  153.    PARAMETERS _mtr_, _mtc_, _mbr_, _mbc_, _mw_, _my_
  154.    *
  155.    _mx_ = SETCOLOR()
  156.    IF PCOUNT()=6
  157.       * color parameter
  158.       SETCOLOR(_my_)
  159.    ENDIF
  160.    *
  161.    @ _mtr_,_mtc_ CLEAR TO _mbr_,_mbc_
  162.    *
  163.    DO CASE
  164.       CASE _mw_ = 1
  165.          * Single line border box
  166.          _mz_ = CHR(218)+CHR(196)+CHR(191)+CHR(179)+CHR(217)+CHR(196)+CHR(192)+CHR(179)
  167.          *
  168.       CASE _mw_ = 2
  169.          * Double line border box
  170.          _mz_ = CHR(201)+CHR(205)+CHR(187)+CHR(186)+CHR(188)+CHR(205)+CHR(200)+CHR(186)
  171.          *
  172.       CASE _mw_ = 3
  173.          * Double line top and bottom and single line sides
  174.          _mz_ = CHR(213)+CHR(205)+CHR(184)+CHR(179)+CHR(190)+CHR(205)+CHR(212)+CHR(179)
  175.          *
  176.       CASE _mw_ = 4
  177.          * Single line top and bottom and double line sides
  178.          _mz_ = CHR(214)+CHR(196)+CHR(183)+CHR(186)+CHR(189)+CHR(196)+CHR(211)+CHR(186)
  179.          *
  180.    ENDCASE
  181.    *
  182.    ****************
  183.    * Draw the box *
  184.    ****************
  185.    @ _mtr_,_mtc_,_mbr_,_mbc_ BOX _mz_
  186.    *
  187.    SETCOLOR(_mx_)
  188. RETURN(.F.)
  189. *
  190. *
  191. *
  192. FUNCTION c_CENTER
  193.    ************************************************************************
  194.    *  PASS:     <expC1>, <expN1>                                          *
  195.    *                                                                      *
  196.    *  RETURNS:  Numeric string                                            *
  197.    *                                                                      *
  198.    *  PURPOSE:  Center messages, character strings, etc. for display or   *
  199.    *            print purposes.  If the length parameter is not passed,   *
  200.    *            function assumes a width of 80.                           *
  201.    *                                                                      *
  202.    *  EXAMPLE:  @ 01,c_CENTER("CUSTOMER REPORT",80) SAY "CUSTOMER REPORT" *
  203.    ************************************************************************
  204.    *
  205.    PARAMETERS _in_string,_in_number
  206.    *
  207.    IF TYPE("_in_number")="U"
  208.       * If length undefined, assume width of 80
  209.       _in_number=80
  210.    ENDIF
  211. RETURN(_in_number / 2 - LEN(_in_string) / 2)
  212. *
  213. *
  214. *
  215. FUNCTION c_CENTRMSG
  216.    ************************************************************************
  217.    *  PASS:     <expC1>                                                   *
  218.    *                                                                      *
  219.    *  RETURNS:  Character string                                          *
  220.    *                                                                      *
  221.    *  PURPOSE:  Works in conjunction with the SET MESSAGE TO and PROMPT   *
  222.    *            commands.  This function will center the character string *
  223.    *            found in the MESSAGE string for each PROMPT command by    *
  224.    *            padding the front of the expression with blank spaces.    *
  225.    *                                                                      *
  226.    *  EXAMPLE:  SET MESSAGE TO 2                                          *
  227.    *            @ 01,23 PROMPT "File Maintenance";+                       *
  228.    *            MESSAGE(c_CNTR_MSG(c_FILL_OUT("Add, Delete, Edit System;  *
  229.    *            Records"))                                                *
  230.    ************************************************************************
  231.    *
  232.    PARAMETERS _in_string,_in_number
  233.    *
  234.    IF TYPE("_in_number")="U"
  235.       * If length undefined, assume width of 80
  236.       _in_number=80
  237.    ENDIF
  238. RETURN(_in_number / 2 - LEN(_in_string) / 2)
  239. *
  240. *
  241. *
  242. FUNCTION c_DATAGONE
  243.    ************************************************************************
  244.    *  PASS:     Nothing                                                   *
  245.    *                                                                      *
  246.    *  RETURNS:  Null                                                      *
  247.    *                                                                      *
  248.    *  PURPOSE:  Removes/empties data from current record.  NOTE this      *
  249.    *            function is designed to be used with the c_BLANK()        *
  250.    *            function.  Overall concept is to blank out data from all  *
  251.    *            fields in a record then reuse the record rather than      *
  252.    *            performing DELETEs and APPEND BLANKs.                     *
  253.    *                                                                      *
  254.    *  EXAMPLE:  c_DATAGONE()                                              *
  255.    ************************************************************************
  256.    *
  257.    PRIVATE _ma_         && Field counter, memvar logic flag
  258.    *
  259.    IF LEN(ALIAS()) <> 0
  260.       * A file is open
  261.       FOR _ma_ = 1 TO FCOUNT()
  262.           _mb_ = FIELDNAME(_ma_)
  263.           IF TYPE("&_mb_.") = "L"
  264.              REPLACE &_mb_. WITH .F.
  265.           ELSE
  266.              REPLACE &_mb_. WITH c_BLANK(&_mb_.)
  267.           ENDIF
  268.       NEXT
  269.    ELSE
  270.       * No file is open or selected
  271.       BREAK
  272.    ENDIF
  273. RETURN(.T.)
  274. *
  275. *
  276. *
  277. FUNCTION c_DECRYPT
  278.    ************************************************************************
  279.    *  PASS:     <expC1>, <expC2> (optional)                               *
  280.    *                                                                      *
  281.    *  RETURNS:  Character string                                          *
  282.    *                                                                      *
  283.    *  PURPOSE:  Use to decrypt a Character string that was encrypted      *
  284.    *            using the c_ENCRYPT() function.                           *
  285.    *  ------------------------------------------------------------------  *
  286.    *  NOTE:  If customization is required, change the value being sub-    *
  287.    *         tracted in the CHR() statement of the FOR...NEXT loop below. *
  288.    *         But beware this value must match that being added in the     *
  289.    *         c_ENCRYPT() function.                                        *
  290.    *                                                                      *
  291.    *  NOTE:  This function requires the c_ALLTRIM() and c_FILL_OUT func-  *
  292.    *         tions to be present during the compile and link cycles.      *
  293.    ************************************************************************
  294.    PARAMETERS _in_string, _in_key
  295.    *
  296.    ****************************************
  297.    * If second parameter has been passed, *
  298.    * add key value to password value      *
  299.    ****************************************
  300.    IF PCOUNT()=2
  301.       _ma_ = LEN(_in_key)
  302.       _mc_ = 0
  303.       _mx_ = 0
  304.       FOR _mc_ = 1 TO (_ma_ + 1)
  305.           _mx_ = _mx_ + ASC(SUBSTR(_in_key,_mc_,1)) * _mc_ + _mc_
  306.       NEXT
  307.    ELSE
  308.       _mx_ = 155        &&  Arbitrary value - may be from 0 to 255 (ASCII)
  309.    ENDIF
  310.    *
  311.    ********************************
  312.    * Decrypt <expC1> *
  313.    ********************************
  314.    _ma_ = LEN(_in_string)
  315.    _mb_ = ""
  316.    _mc_ = 0
  317.    _in_string = c_ALLTRIM(_in_string)
  318.    *
  319.    FOR _mc_ = LEN(_in_string) TO 1 STEP -1
  320.        _mb_ = _mb_ + CHR(ASC(SUBSTR(_in_string,_mc_,1)) - _mx_ )
  321.    NEXT
  322.    *
  323. RETURN(c_FILL_OUT(_mb_,_ma_))
  324. *
  325. *
  326. *
  327. FUNCTION c_ENCRYPT
  328.    ************************************************************************
  329.    *  PASS:     <expC1>, <expC2> (optional)                               *
  330.    *                                                                      *
  331.    *  RETURNS:  Character string                                          *
  332.    *                                                                      *
  333.    *  PURPOSE:  Used to encrypt a Character string that was encrypted     *
  334.    *            using the c_DECRYPT() function.                           *
  335.    *  ------------------------------------------------------------------  *
  336.    *  NOTE:  If customization is required, change the value being added   *
  337.    *         in the CHR() statement of the FOR...NEXT loop below.  But    *
  338.    *         beware this value must match that being subtracted in the    *
  339.    *         c_DECRYPT() function.                                        *
  340.    *                                                                      *
  341.    *  NOTE:  The second character string parameter has been added for     *
  342.    *         even more protection.  If passed, this second parameter is   *
  343.    *         as a "key" value.  The ASCII value of this "key" is added to *
  344.    *         the CHR() value.  If this parameter is used, the value com-  *
  345.    *         puted must match that of the parameter passed in the         *
  346.    *         c_DECRYPT() function.                                        *
  347.    *                                                                      *
  348.    *  NOTE:  This function requires the c_ALLTRIM() and c_FILL_OUT()      *
  349.    *         functions to be present during the compile and link cycles.  *
  350.    ************************************************************************
  351.    PARAMETERS _in_string, _in_key
  352.    *
  353.    ****************************************
  354.    * If second parameter has been passed, *
  355.    * add key value to password value      *
  356.    ****************************************
  357.    IF PCOUNT()=2
  358.       _ma_ = LEN(_in_key)
  359.       _mc_ = 0
  360.       _mx_ = 0
  361.       FOR _mc_ = 1 TO (_ma_ + 1)
  362.           _mx_ = _mx_ + ASC(SUBSTR(_in_key,_mc_,1)) * _mc_ + _mc_
  363.       NEXT
  364.    ELSE
  365.       _mx_ = 155        &&  Arbitrary value - may be from 0 to 255 (ASCII)
  366.    ENDIF
  367.    *
  368.    ********************************
  369.    * Encrypt <expC1> *
  370.    ********************************
  371.    _ma_ = LEN(_in_string)
  372.    _mb_ = ""
  373.    _mc_ = 0
  374.    _in_string = c_ALLTRIM(_in_string)
  375.    *
  376.    FOR _mc_ = LEN(_in_string) TO 1 STEP -1
  377.        _mb_ = _mb_ + CHR(ASC(SUBSTR(_in_string,_mc_,1)) + _mx_ )
  378.    NEXT
  379.    *
  380. RETURN(c_FILL_OUT(_mb_,_ma_))
  381. *
  382. *
  383. *
  384. FUNCTION c_FILL_OUT
  385.    ************************************************************************
  386.    *  PASS:     <expC1>, <expN1>                                          *
  387.    *                                                                      *
  388.    *  RETURNS:  Character string                                          *
  389.    *                                                                      *
  390.    *  PURPOSE:  Pads Character string with spaces defaulting to a width   *
  391.    *            of 79 if no numeric string is passed.                     *
  392.    *                                                                      *
  393.    *  EXAMPLE:  @ 01,23 PROMPT "File Maintenance" MESSAGE(c_CNTR_MSG(;    *
  394.    *            c_FILL_OUT("Add, Delete, Edit System Records"))           *
  395.    *  ------------------------------------------------------------------  *
  396.    *  NOTE:  The UDF c_CNTR_MSG must be present for this function to      *
  397.    *         in the above example.                                        *
  398.    ************************************************************************
  399.    PARAMETERS _mx_,_my_
  400.    *
  401.    IF TYPE("_my_")="U"
  402.       * Length is undefined, default to 79
  403.       _my_=79
  404.    ENDIF
  405.    _mz_=_my_ - LEN(_mx_)
  406. RETURN(_mx_ + SPACE(_mz_))
  407. *
  408. *
  409. *
  410. FUNCTION c_FILLAREA
  411.    ************************************************************************
  412.    *  PASS:     <expN1>, <expN2>, <expN3>, <expN4>, <expN5>               *
  413.    *                                                                      *
  414.    *            where:   <expN1> = top row                                *
  415.    *                     <expN2> = top column                             *
  416.    *                     <expN3> = bottom row                             *
  417.    *                     <expN4> = bottom column                          *
  418.    *                     <expN5> = decimal value of desired character     *
  419.    *                                                                      *
  420.    *  RETURNS:  Nothing                                                   *
  421.    *                                                                      *
  422.    *  PURPOSE:  Used to fill an area on the screen with an ASCII char-    *
  423.    *            acter.                                                    *
  424.    *                                                                      *
  425.    *  EXAMPLE:  c_FILLAREA(10,15,20,25,65)                                *
  426.    ************************************************************************
  427.    PARAMETERS _mtr_, _mtc_, _mbr_, _mbc_, _ma_
  428.    *
  429.    @ _mtr_,_mtc_,_mbr_,_mbc_ BOX REPLICATE(CHR(_ma_),9)
  430.    *
  431. RETURN("")
  432. *
  433. *
  434. *
  435. FUNCTION c_FILLSCRN
  436.    ************************************************************************
  437.    *  PASS:     <expC1>                                                   *
  438.    *                                                                      *
  439.    *  RETURNS:  Null string                                               *
  440.    *                                                                      *
  441.    *  PURPOSE:  Fills entire screen with the character string <expC1>     *
  442.    *            passed.                                                   *
  443.    *                                                                      *
  444.    *  EXAMPLE:  c_FILLSCRN(65)                                            *
  445.    ************************************************************************
  446.    PARAMETERS _ma_
  447.    *
  448.    @ 00,00,24,79 BOX REPLICATE(CHR(_ma_),9)
  449.    *
  450. RETURN("")
  451. *
  452. *
  453. *
  454. FUNCTION c_FIRSTCAP
  455.    ************************************************************************
  456.    *  PASS:     <expC1>                                                   *
  457.    *                                                                      *
  458.    *  RETURNS:  Character string                                          *
  459.    *                                                                      *
  460.    *  PURPOSE:  The first character in the string is capitalized; all     *
  461.    *            remaining characters are in lowercase.                    *
  462.    *                                                                      *
  463.    *  EXAMPLE:  mTITLE=TITLE                   && Field contains "MR."    *
  464.    *            mFIRST=FIRST_NAME              && Field contains "FRED"   *
  465.    *            mLAST=LAST_NAME                && Field contains "JONES"  *
  466.    *                                                                      *
  467.    *            ? c_FIRSTCAP(c_ALLTRIM(mTITLE))+" "+;                     *           
  468.    *              c_FIRSTCAP(c_ALLTRIM(mFIRST))+" "+;                     *
  469.    *              c_FIRSTCAP(c_ALLTRIM(mLAST))                            *
  470.    *                                                                      *
  471.    *            * Output would be "Mr. Fred Jones"                        *
  472.    ************************************************************************
  473.    PARAMETERS _in_string
  474.    *
  475.    _ma_ = SUBSTR(_in_string,1,1)
  476.    _mb_ = SUBSTR(_in_string,2)
  477.    *
  478. RETURN(UPPER(_ma_) + LOWER(_mb_))
  479. *
  480. *
  481. *
  482. FUNCTION c_GATHER
  483.    ************************************************************************
  484.    *  PASS:     Nothing                                                   *
  485.    *                                                                      *
  486.    *  RETURNS:  Null                                                      *
  487.    *                                                                      *
  488.    *  PURPOSE:  Replaces field contents with memory variable values. This *
  489.    *            function is designed to be used with the c_SCATTER func-  *
  490.    *            tion.                                                     *
  491.    *                                                                      *
  492.    *  NOTES:    Memory variable names can be a maximum of 10 characters   *
  493.    *            in length.  This function ASSUMES DATABASE FILE (.DBF)    *
  494.    *            FIELD NAMES TO BE 9 CHARACTERS OR LESS IN LENGTH.         *
  495.    *                                                                      *
  496.    *            If the field is logical in type and the memory variable   *
  497.    *            is character, the function will convert the character     *
  498.    *            string to a logical equivalent.                           *
  499.    *                                                                      *
  500.    *            This function designed to be used in conjunction with     *
  501.    *            the c_SCATTER() UDF.                                      *
  502.    *                                                                      *
  503.    *  EXAMPLE:  c_GATHER()                                                *
  504.    ************************************************************************
  505.    *
  506.    PRIVATE _ma_, _mb_, _mc_       && Counter, field, variable name
  507.    *
  508.    IF LEN(ALIAS()) <> 0
  509.       * A file is open
  510.       FOR _ma_ = 1 TO FCOUNT()
  511.           _mb_ = FIELDNAME(_ma_)
  512.           _mc_ = "M" + _mb_
  513.           *
  514.           IF TYPE("&_mb_.") = "L" .AND. TYPE("&_mc_.") = "C"
  515.              *************************************************************
  516.              * If the field type is logical and the memory variable type *
  517.              * is character, convert the character variable to logical   *
  518.              * before updating the field.                                *
  519.              *************************************************************
  520.              &_mc_. = IF(&_mc_.="Y",.T.,.F.)
  521.           ENDIF
  522.           *
  523.           REPLACE &_mb_. WITH &_mc_.
  524.       NEXT
  525.    ELSE
  526.       * No file is open or selected
  527.       BREAK
  528.    ENDIF
  529. RETURN(.T.)
  530. *
  531. *
  532. *
  533. FUNCTION c_ISESCAPE
  534.    ************************************************************************
  535.    *  PASS:     Nothing                                                   *
  536.    *                                                                      *
  537.    *  RETURNS:  .T. or .F.                                                *
  538.    *                                                                      *
  539.    *  PURPOSE:  Determines if the ESCape key was pressed during a         *
  540.    *            process and cancels.  Will work on a CLIPPER batch        *
  541.    *            statement as well.                                        *
  542.    *                                                                      *
  543.    *  EXAMPLE:  DO WHILE .NOT. EOF()                                      *
  544.    *               ? NAME, ADDRESS, CITY, STATE, ZIP                      *
  545.    *               SKIP                                                   *
  546.    *               IF .NOT. c_ESCAPE                                      *           
  547.    *                  EXIT                                                *
  548.    *               ENDIF                                                  *
  549.    *            ENDDO                                                     *
  550.    *     or                                                               *
  551.    *            LIST ALL NAME,ADDRESS,CITY,STATE,ZIP WHILE c_ISESCAPE()   *
  552.    ************************************************************************
  553.    *
  554.    _ma_ = INKEY()
  555.    *
  556.    IF _ma_ = 27
  557.       RETURN(.F.)
  558.    ENDIF
  559. RETURN(.T.)
  560. *
  561. *
  562. *
  563. FUNCTION c_MEMEMPTY
  564.    ************************************************************************
  565.    *  PASS:     <expC1> (optional)                                        *
  566.    *                                                                      *
  567.    *  RETURNS:  Empty or blank field values.                              *
  568.    *                                                                      *
  569.    *  PURPOSE:  Initializes empty or blank memory variables from record's *
  570.    *            field values.  This function is designed to be used with  *
  571.    *            the c_BLANK(), c_GATHER(), and c_SCATTER() functions.     *
  572.    *                                                                      *
  573.    *  NOTES:    Memory variable names can be a maximum of 10 characters   *
  574.    *            in length.  This function ASSUMES DATABASE FILE (.DBF)    *
  575.    *            FIELD NAMES TO BE 9 CHARACTERS OR LESS IN LENGTH.         *
  576.    *                                                                      *
  577.    *            If a parameter is passed, logical field types will be     *
  578.    *            converted to logical memory variables.  The default       *
  579.    *            assumes no parameter; logical fields are converted to     *
  580.    *            character YES/NO memory variables.  This is done because  *
  581.    *            most user-interface entry screens prompt for Y/N input    *
  582.    *            rather than a .T./.F..                                    *
  583.    *                                                                      *
  584.    *            This function designed to be used with the c_BLANK() UDF. *
  585.    *                                                                      *
  586.    *  EXAMPLE:  c_MEMEMPTY()    && Convert logic field to character       *
  587.    *                            &&    memory variable:  SPACE(1)          *
  588.    *                or                                                    *
  589.    *                                                                      *
  590.    *            c_MEMEMPTY(x)   && Logic field to logic memory variable   *
  591.    ************************************************************************
  592.    *
  593.    PARAMETER _mx_
  594.    *
  595.    PRIVATE _ma_, _mb_, _mc_, _my_       && Counter, field, variable name, logic field flag
  596.    *
  597.    _my_ = IF(PCOUNT()=0,.T.,.F.)
  598.    *
  599.    IF LEN(ALIAS()) <> 0
  600.       * A file is open
  601.       FOR _ma_ = 1 TO FCOUNT()
  602.           _mb_ = FIELDNAME(_ma_)
  603.           _mc_ = "M" + _mb_
  604.           *
  605.           &_mc_. = c_BLANK(&_mb_.)
  606.       NEXT
  607.    ELSE
  608.       * No file is open or selected
  609.       BREAK
  610.    ENDIF
  611. RETURN(.T.)
  612. *
  613. *
  614. *
  615. FUNCTION c_MTC_MENU
  616.    ************************************************************************
  617.    *  PASS:     Row, Column                                               *
  618.    *                                                                      *
  619.    *  RETURNS:  MENU TO amount 1-9                                        *
  620.    *                                                                      *
  621.    *  PURPOSE:  Displays lightbar menu for use with file maintenance      *
  622.    *            programs.                                                 *
  623.    *                                                                      *
  624.    *  EXAMPLE:  DO WHILE .T.                                              *
  625.    *               c_MTC_MENU(row, column)                                *
  626.    *               DO CASE                                                *
  627.    *                  CASE menu_opt=0                                     *           
  628.    *                     EXIT                                             *
  629.    *                     *                                                *
  630.    *                  CASE menu_opt=1                                     *
  631.    *                     DO ADD_PRG                                       *
  632.    *                     ...                                              *
  633.    *                  ...                                                 *
  634.    *                  ...                                                 *
  635.    *               ENDCASE                                                *
  636.    *            ENDDO                                                     *
  637.    *                                                                      *
  638.    *  NOTE:  Remember to initialize the memory variable "menu_opt" with-  *
  639.    *         in the maintenance program.                                  *
  640.    ************************************************************************
  641.    *
  642.    PARAMETERS _ma_,_mb_     
  643.    *
  644.    SET CURSOR OFF
  645.    @ _ma_,_mb_    PROMPT "Add"      MESSAGE "Add a record"
  646.    @ _ma_,COL()+2 PROMPT "Delete"   MESSAGE "Delete displayed record"
  647.    @ _ma_,COL()+2 PROMPT "Edit"     MESSAGE "Edit displayed record"
  648.    @ _ma_,COL()+2 PROMPT "First"    MESSAGE "Go to first record and display"
  649.    @ _ma_,COL()+2 PROMPT "Goto"     MESSAGE "Locate and display a specified record"
  650.    @ _ma_,COL()+2 PROMPT "Hardcopy" MESSAGE "Print displayed record"
  651.    @ _ma_,COL()+2 PROMPT "Last"     MESSAGE "Go to last record and display"
  652.    @ _ma_,COL()+2 PROMPT "Next"     MESSAGE "Go to next record and display"
  653.    @ _ma_,COL()+2 PROMPT "Prev"     MESSAGE "Go to previous record and display"
  654.    MENU TO menu_opt
  655.    *
  656. RETURN(menu_opt)
  657. *
  658. *
  659. *
  660. FUNCTION c_OCCUR
  661.    ************************************************************************
  662.    *  PASS:     <expC1>, <expC2>                                          *
  663.    *                                                                      *
  664.    *  RETURNS:  Numeric string                                            *
  665.    *                                                                      *
  666.    *  PURPOSE:  Returns the number of occurences the first character      *
  667.    *            string appears in the second character string.            *
  668.    ************************************************************************
  669.    PARAMETERS _ma_,_mb_
  670.    *
  671.    _mc_ = 0
  672.    DO WHILE .NOT. EMPTY(AT(_ma_,_mb_))
  673.       _mc_ = _mc_ + 1
  674.       _mb_ = SUBSTR(_mb_, AT(_ma_,_mb_)+1)
  675.    ENDDO
  676. RETURN(_mc_)
  677. *
  678. *
  679. *
  680. FUNCTION c_PASSWORD
  681.    ************************************************************************
  682.    *  PASS:     <expC1>, <expC2> (optional)                               *
  683.    *                                                                      *
  684.    *  RETURNS:  Numeric string                                            *
  685.    *                                                                      *
  686.    *  PURPOSE:  Generates a numeric value for any string based on the     *
  687.    *            ASCII value of each character multiplied by its relative  *
  688.    *            position in the character string.                         *
  689.    *                                                                      *
  690.    *  EXAMPLE:  In the following code, a second parameter has been        *
  691.    *            (mpw_key).                                                *
  692.    *                                                                      *
  693.    *            mpw_key = "@!$xYz&*+"                                     *
  694.    *            USE PASSWORD.DBF                                          *
  695.    *            mpassword= SPACE(10)                                      *
  696.    *            @ 1,5 SAY "ENTER PASSWORD " GET mpassword                 *
  697.    *            READ                                                      *
  698.    *            IF mpassword=SPACE(10)                                    *
  699.    *               QUIT                                                   *
  700.    *            ELSE                                                      *
  701.    *               LOCATE FOR c_PASSWORD(mpassword,mpw_key)=PW            *
  702.    *               IF EOF()                                               *
  703.    *                  ?? CHR(7)                                           *
  704.    *                  @ 5,5 SAY "INVALID PASSWORD"                        *
  705.    *               ELSE                                                   *
  706.    *                  .....                                               *
  707.    *                  other commands                                      *
  708.    *                  .....                                               *
  709.    *               ENDIF                                                  *
  710.    *            ENDIF                                                     *
  711.    *                                                                      *
  712.    *  ------------------------------------------------------------------  *
  713.    *  NOTE:  As a added precaution, if the second parameter has been      *
  714.    *         passed it is added into the overall value that is returned.  *
  715.    *         This "key" value can be hardcoded in the main module or      *
  716.    *         placed in a type of data (.MEM, .DBF) file prior to branch-  *
  717.    *         ing to the password verification routine.                    *
  718.    *                                                                      *
  719.    ************************************************************************
  720.    PARAMETERS _in_string, _in_key
  721.    *
  722.    _ma_ = LEN(TRIM(_in_string))
  723.    _mb_ = 0
  724.    *
  725.    **************************
  726.    * Compute password value *
  727.    **************************
  728.    FOR _mc_ = 1 TO (_ma_ + 1)
  729.        _mb_ = _mb_ + ASC(SUBSTR(_in_string,_mc_,1)) * _mc_
  730.    NEXT
  731.    *
  732.    ****************************************
  733.    * If second parameter has been passed, *
  734.    * add key value to password value      *
  735.    ****************************************
  736.    IF PCOUNT()=2
  737.       _ma_ = LEN(TRIM(_in_key))
  738.       FOR _mc_ = 1 TO (_ma_ + 1)
  739.           _mb_ = _mb_ + ASC(SUBSTR(_in_string,_mc_,1)) * _mc_
  740.       NEXT
  741.    ENDIF
  742.    *
  743. RETURN(_mb_)
  744. *
  745. *
  746. *
  747. FUNCTION c_PERCENT
  748.    ************************************************************************
  749.    *  PASS:     <expN1>, <expN2>                                          *
  750.    *                                                                      *
  751.    *  RETURNS:  Character string                                          *
  752.    *                                                                      *
  753.    *  PURPOSE:  Returns a Character string in the format of a percentage. *
  754.    *            The calculation is based on the first expression divided  *
  755.    *            by the second expression.                                 *
  756.    *                                                                      *
  757.    * EXAMPLE:                                                             *
  758.    *                                                                      *
  759.    ************************************************************************
  760.    PARAMETERS _ma_,_mb_
  761.    *
  762.    IF PCOUNT()=0 .OR. _mb_=0
  763.       RETURN("")
  764.    ENDIF
  765.    *
  766. RETURN(TRANSFORM(_ma_ / _mb_ , "###.##%"))
  767. *
  768. *
  769. *
  770. FUNCTION c_RANDOM
  771.    ************************************************************************
  772.    *  PASS:     <expN1>                                                   *
  773.    *                                                                      *
  774.    *  RETURNS:  Numeric string                                            *
  775.    *                                                                      *
  776.    *  PURPOSE:  Returns a random number based on the number passed to it. *
  777.    *                                                                      *
  778.    *  EXAMPLE:                                                            *
  779.    *                                                                      *
  780.    ************************************************************************
  781.    PARAMETERS _ma_
  782.    *
  783.    _mb_ = (_ma_ < 0)
  784.    *
  785.    IF _ma_ = 0
  786.       RETURN(0) 
  787.    ENDIF
  788.    *
  789.    _ma_ = ABS(_ma_)
  790.    _mc_ = SECONDS()/100
  791.    _md_ = (_mc_ - INT(_mc_)) * 100
  792.    _me_ = LOG(SQRT(SECONDS()/100))
  793.    _mf_ = (_me_ - INT(_me_)) * 100
  794.    _mg_ = (_md_ * _mf_)
  795.    _mh_ = _mg_ - INT(_mg_)
  796.    _mi_ = _ma_ * _mh_
  797.    _mj_ = ROUND(_mi_,2)
  798.    _mk_ = INT(_mj_)+IF(INT(_mj_)+1 < _ma_ + 1,1,0)
  799.    *
  800. RETURN(_mk_ * IF(_mb_, -1, 1))
  801. *
  802. *
  803. *
  804. FUNCTION c_RJUST
  805.    ************************************************************************
  806.    *  PASS:     <expC1>, <expN1>                                          *
  807.    *                                                                      *
  808.    *  RETURNS:  Numeric string                                            *
  809.    *                                                                      *
  810.    *  PURPOSE:  Modifies the Character string and returns a column pos-   *
  811.    *            ition that, if used, would right-justify the string to    *
  812.    *            the numeric expressions of the Nth column position.  If   *
  813.    *            not used, the default value for the numeric expression    *
  814.    *            will be 79.                                               *
  815.    *                                                                      *
  816.    *  EXAMPLE:  @ 01,00 CLEAR                                             *
  817.    *            @ 01,c_RJUST("Customer") SAY "Customer"                   *
  818.    *************************************************************************
  819.    PARAMETERS _in_string,_in_number
  820.    *
  821.    IF PCOUNT()=1
  822.       _in_number=79
  823.    ENDIF
  824.    *
  825. RETURN(IF(LEN(_in_string) > _in_number, _in_string, _in_number - LEN(_in_string)))
  826. *
  827. *
  828. *
  829. FUNCTION c_RJUSTSTR
  830.    ************************************************************************
  831.    *  PASS:     <expC1>                                                   *
  832.    *                                                                      *
  833.    *  RETURNS:  Right Justified Character string                          *
  834.    *                                                                      *
  835.    *  PURPOSE:  Modifies the character string and returns the character   *
  836.    *            string in a right justified state.  Note this differs     *
  837.    *            from the c_RJUST() function in that the character string  *
  838.    *            is permanently altered.                                   *
  839.    *                                                                      *
  840.    *  EXAMPLE:  mcustno=SPACE(6)                                          *
  841.    *            @ 12,10 SAY "Enter Customer Number "                      *
  842.    *            @ 12,COL()+1 GET mcustno PICTURE "999999"                 *
  843.    *            READ                                                      *
  844.    *                                                                      *
  845.    *                   &&  if "12" was entered, mcustno would appear as   *
  846.    *                   &&      12----                                     *
  847.    *                   &&  where "-" indicates trailing spaces            *
  848.    *                                                                      *
  849.    *            mcustno = c_RJUSTSTR(mcustno)                             *
  850.    *                                                                      *
  851.    *                   &&  mcustno now contains                           *
  852.    *                   &&      ----12                                     *
  853.    *                   &&  where "-" indicates leading spaces             *
  854.    ************************************************************************
  855.    *
  856.    PARAMETERS _ma_
  857.    *
  858.    IF TYPE("_ma_")="C"
  859.       _mb_ = LEN(_ma_)
  860.       _ma_ = LTRIM(TRIM(_ma_))
  861.       *
  862.       IF LEN(_ma_) < _mb_
  863.          FOR _mx_ = LEN(_ma_) TO (_mb_ -1)
  864.              _ma_ = " "+_ma_
  865.          NEXT
  866.       ENDIF
  867.    ENDIF
  868. RETURN(_ma_)
  869. *
  870. *
  871. *
  872. FUNCTION c_ROUND
  873.    ************************************************************************
  874.    *  PASS:     <expN1>                                                   *
  875.    *                                                                      *
  876.    *  RETURNS:  Numeric string                                            *
  877.    *                                                                      *
  878.    *  PURPOSE:  Rounds 2 Numeric string to 2 decimal positions.  Its      *
  879.    *            reliable than the CLIPPER counterpart.                    *
  880.    *                                                                      *
  881.    *  EXAMPLE:  x = 456.78 / 789.01                                       *
  882.    *            ? c_ROUND(x)                                              *
  883.    ************************************************************************
  884.    PARAMETERS _in_number
  885.    *
  886.    _in_number = INT(_in_number * 100 + .5) / 100.00
  887.    *
  888. RETURN(_in_number)
  889. *
  890. *
  891. *
  892. FUNCTION c_SAYIT
  893.    ************************************************************************
  894.    *  PASS:     <expN1>, <expN2>, <expC1>, <expC2> (optional)             *
  895.    *                                                                      *
  896.    *            where:   <expN1> = row                                    *
  897.    *                     <expN2> = column                                 *
  898.    *                     <expC1> = message, heading, etc.                 *
  899.    *                     <expC2> = optional message color parameter       *
  900.    *                                                                      *
  901.    *  RETURNS:  Nothing                                                   *
  902.    *                                                                      *
  903.    *  PURPOSE:  Displays screen message in specified color.               *
  904.    *                                                                      *
  905.    *  EXAMPLE:  mmsg = "Enter Name "     && message                       *
  906.    *            msaycolor = "+BG/N"      && color variable                *
  907.    *            *                                                         *
  908.    *             c_SAYIT(05,10,mmsg,msaycolor)                            *
  909.    *                                                                      *
  910.    ************************************************************************
  911.    PARAMETERS _ma_, _mb_, _mc_, _md_
  912.    *
  913.    _mx_ = SETCOLOR()
  914.    IF PCOUNT()=4
  915.       * color parameter
  916.       SETCOLOR(_md_)
  917.    ENDIF
  918.    *
  919.    @ _ma_,_mb_ SAY _mc_
  920.    *
  921.    SETCOLOR(_mx_)
  922. RETURN(.F.)
  923. *
  924. *
  925. *
  926. FUNCTION c_SCATTER
  927.    ************************************************************************
  928.    *  PASS:     <expC1> (optional)                                        *
  929.    *                                                                      *
  930.    *  RETURNS:  Null                                                      *
  931.    *                                                                      *
  932.    *  PURPOSE:  Initializes memory variables from record's field values.  *
  933.    *                                                                      *
  934.    *  NOTES:    Memory variable names are prefixed with an uppercase "M"  *
  935.    *            due to CLIPPER requirements of input_var names in system  *
  936.    *            HELP programs.                                            *
  937.    *                                                                      *
  938.    *            Memory variable names can be a maximum of 10 characters   *
  939.    *            in length.  This function ASSUMES DATABASE FILE (.DBF)    *
  940.    *            FIELD NAMES TO BE 9 CHARACTERS OR LESS IN LENGTH.         *
  941.    *                                                                      *
  942.    *            If a parameter is passed, logical field types will be     *
  943.    *            converted to logical memory variables.  The default       *
  944.    *            assumes no parameter; logical fields are converted to     *
  945.    *            character YES/NO memory variables.  This is done because  *
  946.    *            most user-interface entry screens prompt for Y/N input    *
  947.    *            rather than a .T. / .F..                                  *
  948.    *                                                                      *
  949.    *  EXAMPLE:  c_SCATTER()     && Convert logic field to character       *
  950.    *                            &&    memory variable                     *
  951.    *                or                                                    *
  952.    *                                                                      *
  953.    *            c_SCATTER(x)    && Logic field to logic memory variable   *
  954.    ************************************************************************
  955.    *
  956.    PARAMETER _mx_
  957.    *
  958.    PRIVATE _ma_, _mb_, _mc_, _my_      && Counter, field, variable name, logic flag
  959.    *
  960.    _my_ = IF(PCOUNT()=0,.T.,.F.)
  961.    *
  962.    IF LEN(ALIAS()) <> 0
  963.       * A file is open
  964.       FOR _ma_ = 1 TO FCOUNT()
  965.           _mb_ = FIELDNAME(_ma_)
  966.           _mc_ = "M" + _mb_
  967.           *
  968.           IF TYPE("&_mb_.") = "L" .AND. _my_
  969.              ****************************************************
  970.              * Convert logic field to character memory variable *
  971.              ****************************************************
  972.              &_mc_. = IF(&_mb_.,"Y","N")
  973.           ELSE
  974.              &_mc_. = &_mb_.
  975.           ENDIF
  976.       NEXT
  977.    ELSE
  978.       * No file is open or selected
  979.       BREAK
  980.    ENDIF
  981. RETURN(.T.)
  982. *
  983. *
  984. *
  985. FUNCTION c_SHADOW
  986.    ************************************************************************
  987.    *  PASS:     <expN1>, <expN2>, <expN3>, <expN4>                        *
  988.    *                                                                      *
  989.    *            where:   <expN1> = top row                                *
  990.    *                     <expN2> = top column                             *
  991.    *                     <expN3> = bottom row                             *
  992.    *                     <expN4> = bottom column                          *
  993.    *                                                                      *
  994.    *  RETURNS:  Nothing                                                   *
  995.    *                                                                      *
  996.    *  PURPOSE:  Used to display a shadow around a box or menu area drawn  *
  997.    *            by either the BOX command or the @... SAY... DOUBLE       *
  998.    *            command.                                                  *
  999.    *                                                                      *
  1000.    *  EXAMPLE:  @ 15,15 CLEAR TO 20,45                                    *
  1001.    *            @ 15,15 TO 20,45 DOUBLE                                   *
  1002.    *            c_SHADOW(15,15,20,45)                                     *
  1003.    ************************************************************************
  1004.    PARAMETERS _mtr_, _mtc_, _mbr_, _mbc_
  1005.    *
  1006.    _in_color = SETCOLOR()
  1007.    SETCOLOR(STRTRAN(_in_color, "+", "" ))
  1008.    *
  1009.    FOR _mx_ = _mtr_ + 1 TO _mbr_ + 1
  1010.       @ _mx_, _mbc_ + 1 SAY CHR(177)
  1011.    NEXT
  1012.    *
  1013.    @ _mx_ -1, _mtc_ + 1 SAY REPLICATE(CHR(177), _mbc_ - _mtc_ )
  1014.    *
  1015.    SETCOLOR(_in_color)
  1016. RETURN(.F.)
  1017. *
  1018. *
  1019. *
  1020.  
  1021.  
  1022.  
  1023.