' FILEREC%(0.0)  Count Number of File Records              06/02/2001-02/09/2010
' ------------------------------------------------------------------------------
' Copyright (C) 2001-2010 by Vladimir Veytsel                      pbc.davar.net

' Type -------------------------------------------------------------------------

'    Function

' Parameter --------------------------------------------------------------------

'    File_Name$  - File name

' Value ------------------------------------------------------------------------

'    IF specified file exists,
'       THEN file is opened, read through, while counting number of its
'            records, closed, and record counter is returned to the point
'            of function invocation;
'       ELSE -1 is returned to the point of function invocation to indicate
'            a problem to the calling program.

' Start Function ---------------------------------------------------------------

     FUNCTION FILEREC%(File_Name$)

' Check File Specification Validity and Count Number of It's Records -----------

     IF ((File_Name$="")            OR _
         (LEN(DIR$(File_Name$))=0)) THEN
        File_Records%=-1
     ELSE
        OPEN File_Name$ FOR INPUT AS #1
        WHILE NOT EOF(1)
              LINE INPUT #1, Record$
              File_Records%=File_Records%+1
        WEND
        CLOSE #1
     END IF

' Return Function Value to the Point of Invocation -----------------------------

     FILEREC%=File_Records%

' Finish Function --------------------------------------------------------------

     END FUNCTION