home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / serialno.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  101 lines

  1. /*
  2.  * File......: SERIALNO.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_SERIALNUMBER()
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *      Generate a serial number i.e. the next number in a series.
  28.  *  $SYNTAX$
  29.  *      GT_SerialNumber( cAlias , lError )
  30.  *  $ARGUMENTS$
  31.  *      cAlias - Alias of table
  32.  *      lError - If .T. generate an error message if failed
  33.  *  $RETURNS$
  34.  *      The next serial number in the sequence
  35.  *      -1 if the record could not be locked
  36.  *  $DESCRIPTION$
  37.  *      Generate a serial number i.e. the next number in a series.
  38.  *      Assumes that cAlias is a table containing one field - a numeric
  39.  *      of unspecified name, and only one record.
  40.  *  $EXAMPLES$
  41.  *
  42.  *  $SEEALSO$
  43.  *
  44.  *  $INCLUDE$
  45.  *      GT_LIB.CH
  46.  *  $END$
  47.  */
  48. *
  49. #include "GT_lib.ch"
  50.  
  51. FUNCTION GT_SerialNumber( cAlias , lError )
  52.  
  53. /*****************************************************************************
  54.  Purpose - Generate a serial number i.e. the next number in a series.
  55.            Assumes that cAlias is a table containing one field - a numeric
  56.            of unspecified name, and only one record.
  57.  Returns - A numeric that is one greater than the contents of the field
  58.            If the record could not be locked, -1 is returned.
  59.  Author  - Log
  60.  Created - 26/10/92
  61. ******************************************************************************
  62.  Parameters - cAlias - Table to take field from
  63.               lError - If .T., display an error message
  64.  Privates   - None
  65.  Locals     - nValue - Value to return
  66.  Externals  - None
  67. *****************************************************************************/
  68.  
  69. LOCAL cCurrent := ALIAS()
  70. LOCAL xReturn
  71.  
  72. DEFAULT lError TO .F.
  73.  
  74. * Select the work area
  75. SELECT ( cAlias )
  76.  
  77. * Try to lock the record
  78. IF GT_RecLock( 0 )
  79.     * Record locked, so increment the field
  80.     FIELDPUT( 1 , FIELDGET( 1 ) + 1 )
  81.  
  82.     * Unlock the record
  83.     UNLOCK
  84.  
  85.     * Return the value
  86.     xReturn := FIELDGET( 1 )
  87. ELSE
  88.     * Do we generate an error message ?
  89.     IF lError
  90.         GT_Warning( { "Could not get serial number" } )
  91.     ENDIF
  92.  
  93.     * Return the error value
  94.     xReturn := -1
  95. ENDIF
  96.  
  97. SELECT ( cCurrent )
  98.  
  99. RETURN( xReturn )
  100. *
  101.