home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / dba0187.zip / VALIDATE.PRG < prev   
Text File  |  1986-12-05  |  7KB  |  200 lines

  1. * VALIDATE.PRG         08/26/86
  2. *
  3. * this program is a set of GETFILE validation procedures
  4. *
  5.  
  6. PROCEDURE STATEVAL.PRG
  7.   * STATEVAL.PRG
  8.   *
  9.   * written by: Bob Green    date    : 04/26/86
  10.   *                             modified: 08/24/86
  11.   *
  12.   * this is a GETFILE program to validate that the entry of a
  13.   * field contains a valid U.S.P.S. two-letter state abbreviation.
  14.   * the calling program must use a statement as follows:
  15.   *
  16.   * @ xx,yy SAY "desired input text" GET variable PICTURE "!!" ;
  17.   *            GETFILE stateval.prg
  18.   *
  19.   * this routine works with dBMAN V2.0 or later
  20.  
  21.   * set up a getfile-routine field containing the name of
  22.   * the field `get' field that was `read' by the calling program
  23.   STORE GETNAME() TO y.getfld
  24.  
  25.   * set up a variable that contains the valid state abbrev's
  26.   STORE "AL|AK|AZ|AR|CA|CO|CT|DE|DC|FL|GA|HI|ID|IL|IN|IA|"+;
  27.         "KS|KY|LA|ME|MD|MA|MI|MN|MS|MO|MT|NE|NV|NH|NJ|NY|"+;
  28.         "NC|ND|OH|OK|OR|PA|PR|RI|SC|SD|TN|TX|UT|VT|VA|WA|"+;
  29.         "WV|WI|WY" TO y.valid_st
  30.  
  31.   * use a macro substitution for the field name when determining
  32.   * if the field READ was valid
  33.   IF INSET("|",&y.getfld,y.valid_st) = 0
  34.  
  35.      * the field entered is not valid, write an error message on the
  36.      * screen, and perform your standard validation error routine
  37.      STORE "'"+&y.getfld+"' IS NOT A VALID STATE" TO m_errmsg
  38.      DO errmsg.prg
  39.  
  40.      * force the same field to be READ again
  41.      ASSIGN USERSTAT(0)
  42.  
  43.   ENDIF
  44.   RETURN
  45.  
  46. PROCEDURE STRNGVAL.PRG
  47.   * STRNGVAL.PRG
  48.   *
  49.   * written by:  Bob Green     date:         08/14/86
  50.   *                               modified:
  51.   *
  52.   * this getfile program validates the entered string is among the
  53.   * valid strings for this variable.  The calling program must have
  54.   * the following two statements:
  55.   *  1)  y.YYYYYYYYYX = "valid    |strings  |separated|by bars  "
  56.   *
  57.   *      where - `YYYYYYYYY' is up to the first 9 characters of the
  58.   *               GET variables name.  An `X' is appended to the GET
  59.   *               variable name to make it unique.
  60.   *            -  the valid strings must be the same length as the GET
  61.   *               variable and separated by bars (`|')
  62. .
  63.   *
  64.   *  2)  @ xx,yy SAY "desired input text" GET variable PICTURE "!!" ;
  65.   *                 GETFILE strngval.prg
  66.   *
  67.   *   this routine works with dBMAN V2.0 or later
  68.  
  69.   * set up a getfile-routine field containing the name of
  70.   * the field `get' field that was `read' by the calling program
  71.   STORE GETNAME() TO y.getfld
  72.  
  73.   * set up a variable containing the string validation variable name
  74.   STORE SUBSTR(TRIM(y.getfld),1,9)+"X" TO y.valid_str
  75.  
  76.   * use a macro substitution for the field name when determining
  77.   * if the field READ was valid
  78.   IF INSET("|",&y.getfld,&y.valid_str) = 0
  79.  
  80.      * the field entered is not valid, write an error message on the
  81.      * screen, and perform your standard validation error routine
  82.      STORE "`"+&y.getfld+"' IS NOT A VALID RESPONSE" TO m_errmsg
  83.      DO errmsg.prg
  84.  
  85.      * force the same field to be READ again
  86.      ASSIGN USERSTAT(0)
  87.  
  88.   ENDIF
  89.   RETURN
  90.  
  91. PROCEDURE FILEVAL.PRG
  92.   * FILEVAL.PRG
  93.   *
  94.   * written by:  Bob Green     date:  08/14/86
  95.   *                        modified:
  96.   *
  97.   * this getfile program validates the variable entered is a key on
  98.   * the master index of a file.  Since dBMAN does not require a file
  99.   * be SELECTed to be used, the file validation can be on any open
  100.   * file.  The calling program must have the following two statements:
  101.   *
  102.   *  1)  y.zzzzzzzzzX = "Fi"
  103.   *
  104.   *      where - `zzzzzzzzz' is up to the first 9 characters of the
  105.   *               GET variables name.  An `X' is appended to these
  106.   *               characters to make a new, unique variable.
  107.   *            -  `Fi' is the file id of file to validate against. The
  108.   *                file id must be for a valid, open file (`FJ' - `FS')
  109.   *
  110.   *  2)  @ xx,yy SAY "desired input text" GET variable PICTURE <fmt> ;
  111.   *                 GETFILE fileval.prg
  112.   *
  113.   *   this routine works with dBMAN V2.0 or later
  114.  
  115.   * set up a getfile-routine field containing the name of
  116.   * the `get' field that was `read' by the calling program
  117.   STORE GETNAME() TO y.getfld
  118.  
  119.   * set up a variable that contains the file id to validate against
  120.   STORE SUBSTR(TRIM(y.getfld),1,9)+"X" TO y.valid_file
  121.  
  122.   * use a macro substitution for the field name and the file id to
  123.   * determine if the field READ was valid
  124.   STORE "FIND "+&y.valid_file+" '"+ ;
  125.         &y.getfld+"'" TO y.cmd
  126.   &y.cmd
  127.   STORE "IF EOF("+&y.valid_file+")" to y.cmd
  128.   &y.cmd
  129.      * the field entered is not valid, write an error message on the
  130.      * screen, and perform your standard validation error routine
  131.      STORE "`"+&y.getfld+"' IS NOT ON FILE" TO m_errmsg
  132.      DO errmsg.prg
  133.  
  134.      * force the same field to be READ again
  135.      ASSIGN USERSTAT(0)
  136.  
  137.   ENDIF
  138.   RETURN
  139.  
  140. PROCEDURE RANGE.PRG
  141.   * RANGE.PRG
  142.   *
  143.   * written by:  Bob Green     date:  08/14/86
  144.   *                        modified:
  145.   *
  146.   * this getfile program validates the entered number is within the
  147.   * valid range for this variable.  The calling program must have
  148.   * the following two statements:
  149.   *  1)  y.YYYYYYYYYX = "LLLL.L|HHHH.HHH"
  150.   *
  151.   *         where - `YYYYYYYYY' is up to the first 9 characters of the
  152.   *                  GET variables name.  An `X' is appended to the GET
  153.   *                  variable name to make it unique.
  154.   *               -  LLLL is the lower limit allowed for the variable
  155.   *                  HHHH is the upper limit allowed for the variable
  156.   *
  157.   *  2)  @ xx,yy SAY "desired input text" GET variable PICTURE "99" ;
  158.   *                 GETFILE range.prg
  159.   *
  160.   *   this routine works with dBMAN V2.0 or later
  161.  
  162.   * set up a getfile-routine field containing the name of
  163.   * the field `get' field that was `read' by the calling program
  164.   STORE GETNAME() TO y.getfld
  165.  
  166.   * set up a variable containing the string validation variable name
  167.   STORE SUBSTR(TRIM(y.getfld),1,9)+"X" TO y.valid_str
  168.  
  169.   * use a macro substitution for the field name when determining
  170.   * lower and upper limits for the variable entered
  171.   STORE VAL($(&y.valid_str,1,AT("|",&y.valid_str)-1)) TO y.low
  172.   STORE VAL($(&y.valid_str,AT("|",&y.valid_str)+1))   TO y.high
  173.   * if the field READ was valid
  174.   IF &y.getfld < y.low OR &y.getfld > y.high
  175.  
  176.      * the field entered is not valid, write an error message on the
  177.      * screen, and perform your standard validation error routine
  178.      STORE "ENTRY MUST BE BETWEEN " + ;
  179.             $(&y.valid_str,1,AT("|",&y.valid_str)-1) + " AND " + ;
  180.             $(&y.valid_str,AT("|",&y.valid_str)+1) TO m_errmsg
  181.      DO errmsg.prg
  182.  
  183.      * force the same field to be READ again
  184.      ASSIGN USERSTAT(0)
  185.  
  186.   ENDIF
  187.   RETURN
  188.  
  189. PROCEDURE ERRMSG.PRG
  190.   * ERRMSG.PRG         11/23/84   BOB GREEN
  191.   @ 23,INT((64-LEN(m_errmsg))/2) SAY "*** ERROR - "+m_errmsg+" ***"
  192.   @ 24,27 SAY "PRESS ANY KEY TO CONTINUE"
  193.   BEEP
  194.   SET CONSOLE OFF
  195.   WAIT
  196.   SET CONSOLE ON
  197.   @ 23,0
  198.   @ 24,0
  199.   RETURN
  200.