Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- The Guide To Clipper - <b>dup_chk() duplicate entry validation apndxj.prg</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Dup_chk()      Duplicate entry validation              Apndxj.prg


Syntax:        Dup_chk(<variable>, <work area>)

Argument:      <variable> is the name of the current GET variable.

               <work area> is the work area number where you want to
               make the lookup.

Returns:       True (.T.) if a matching record is not found in <alias>.

Description:   Dup_Chk() is a validation function you can use with the
               VALID clause of @...GET.  Its primary function is to
               perform a lookup in a specified work area and return an
               error if a matching record is found.  Prior to performing
               the lookup check, two other checks are made.  First, if
               the GET variable is blank, Dup_Chk() returns true (.T.).
               Second, if the GET variable is not completely filled, an
               error message displays and Dup_Chk() returns false (.F.).


--------------------------------- Source Code ------------------------------

   FUNCTION Dup_Chk

   PARAMETERS dup_no, workarea

   * An empty value is acceptable.
   IF EMPTY(dup_no)
      RETURN .T.
   ENDIF

   * Integrity check.
   IF LEN(TRIM(dup_no)) < LEN(dup_no)
      Err_msg("Field not completely filled")
      RETURN .F.
   ENDIF

   * Duplicate check.
   lastarea = SELECT()
   SELECT workarea
   SEEK dup_no
   IF FOUND()
      Err_msg("Already on file")
      validation = .F.
   ELSE
      validation = .T.
   ENDIF
   SELECT (lastarea)
   RETURN validation


-----------------------------------  Err_msg() --------------------------------

   FUNCTION Err_msg

   PARAMETERS msg

   SAVE SCREEN
   row = 7
   msg = msg + ", press any key..."
   col = INT((80 - LEN(msg))/2) - 2
   @ row, col CLEAR TO row + 2, col + LEN(msg) + 4
   @ row, col TO row + 2, col + LEN(msg) + 4 DOUBLE
   @ row + 1, col + 2 SAY msg
   INKEY(0)
   RESTORE SCREEN

   RETURN ""


See Also: @...SAY...GET

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson