|
FILEREC% PowerBASIC Function |
|
FILEREC% function evaluates to the number of records of a file that is specified as function parameter. If file name is incorrect, or file doesn't exist, function evaluates to "-1" that is an error indicator for an invoking program. FILEREC% Source Program Debugging program Debugging logout |
' FILEREC%(0.0) Count Number of File Records 06/02/2001-06/02/2001
' --------------------------------------------------------------------------
' Copyright (C) 2001 by Vladimir Veytsel www.davar.net
' Type ---------------------------------------------------------------------
' Function
' Declaration --------------------------------------------------------------
' DECLARE FUNCTION FILEREC%(File.Name$)
' Parameter ----------------------------------------------------------------
' File.Name$ - File name
' Value --------------------------------------------------------------------
' If specified file exists,
' then file is opened, read through, while counting number of it's
' 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$) PUBLIC
' 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
|
FILEREC% Debugging Program Source program Debugging logout |
' FILEREC%(0.0) Count Number of File Records 06/02/2001-06/02/2001
' --------------------------------------------------------------------------
$INCLUDE "FILEREC"
DECLARE FUNCTION FILEREC%(File.Name$)
CLS
PRINT "FILEREC%(0.0) Count Number of File Records "; DATE$;
PRINT " "; LEFT$(TIME$,5)
PRINT STRING$(62,"-")
PRINT
PRINT "FILEREC%('')="; _
FILEREC%("")
PRINT
PRINT "FILEREC%('C:\PBASIC\ZZZZZZZ.ZZZ')="; _
FILEREC%("C:\PBASIC\ZZZZZZZ.ZZZ")
PRINT
PRINT "FILEREC%('C:\PBASIC\FILEREC.BAS')="; _
FILEREC%("C:\PBASIC\FILEREC.BAS")
PRINT
PRINT "Execution completed - hit [Enter] to continue..."
|
FILEREC% Debugging Logout Source program Debugging program |
FILEREC%(0.0) Count Number of File Records 12-06-2007 08:18
--------------------------------------------------------------
FILEREC%('')=-1
FILEREC%('C:\PBASIC\ZZZZZZZ.ZZZ')=-1
FILEREC%('C:\PBASIC\FILEREC.BAS')= 50
Execution completed - hit [Enter] to continue...
|
|
View [and save] FILEREC.BAS text View [and save] ZFILEREC.BAS text (Use [Back] button or [Alt]+[CL] to return here from the viewed text) Copyright © 2001 by Go to: Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top |