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

  1. /*
  2.  * File......: LASTREC.PRG
  3.  * Author....: Dave Pearson
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Dave Pearson
  7.  * Date......: $Date$
  8.  * Revision..: $Revision$
  9.  * Log file..: $Logfile$
  10.  *
  11.  * This is an original work by Dave Pearson and is placed in the public
  12.  * domain.
  13.  *
  14.  * Modification history:
  15.  * ---------------------
  16.  *
  17.  * $Log$
  18.  *
  19.  */
  20.  
  21. #include "gt_lib.ch"
  22.  
  23. /*  $DOC$
  24.  *  $FUNCNAME$
  25.  *      GT_LASTREC()
  26.  *  $CATEGORY$
  27.  *      File I/O
  28.  *  $ONELINER$
  29.  *      Get the count of records in a DBF file.
  30.  *  $SYNTAX$
  31.  *      GT_LastRec(<cFileName>) --> nNumberOfRecords
  32.  *  $ARGUMENTS$
  33.  *      <cFileName> is the name of the DBF file. If the name has no
  34.  *      extension it defaults to DBF.
  35.  *  $RETURNS$
  36.  *      The number of records in the DBF file.
  37.  *  $DESCRIPTION$
  38.  *      GT_LastRec() is designed to be the same as the Clipper function
  39.  *      LastRec(). The main change is that it works on un-opened database
  40.  *      files.
  41.  *  $EXAMPLES$
  42.  *      // Print the number of records in a database file.
  43.  *
  44.  *      ? GT_LastRec("Life")
  45.  *  $END$
  46.  */
  47.  
  48. function GT_LastRec(cFileName)
  49. local nFile    := 0     ,;
  50.       cLastRec := "    ",;
  51.       nLastRec := 0
  52. if valtype(cFileName) == TYPE_CHAR
  53.    if GT_IsDbf(cFileName)
  54.       cFileName := GT_DefExt(cFileName,"Dbf")
  55.       if (nFile := fopen(cFileName,FO_READ)) != F_ERROR
  56.          fseek(nFile,4,FS_SET)
  57.          if fread(nFile,@cLastRec,4) == 4
  58.             nLastRec := bin2l(cLastRec)
  59.          endif
  60.          fclose(nFile)
  61.       endif
  62.    endif
  63. endif
  64. return(nLastRec)
  65.