From: Steve on
I am using the End Of File (EOF) function within a simple function to
count records in a text file. I have never had problems with this
function
until I began using it to count records in text files which include
lower
value ascii characters in the source text files.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Function Count_Records(strFilePath As String) As Long
'Receive a path to a text file, and count the number of lines
(records)
'If file doesn't exist, then function returns a value of ZERO

Dim intFileNum As Integer
Dim strCurLine As String
Dim lngFileLen As Long
Dim lngRecCtr As Long
Dim blnPathIsInvalid as boolean

On Error GoTo errHandler

lngFileLen = FileLen(strFilePath)

if blnPathIsInvalid then
intFileNum = FreeFile()
Open strFilePath For Input As intFileNum

Do Until EOF(intFileNum)
Line Input #intFileNum, strCurLine
lngRecCtr = lngRecCtr + 1
Loop
Close intFileNum
end if

Count_Records = lngRecCtr

Exit Function 'Bypass Error Handling
errHandler:
blnPathIsInvalid=True
resume next

End Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What happens is after the first line of the text file is read via the
Line Input# function, the EOF function suddenly returns a TRUE value
and terminates the loop. Of course, there are many more lines of
text in the source text file which need to be counted.

The structure of the text lines contains regulated data such as ...
Ascii Data (32 ~126) + chr(14) + Ascii Data(32~126) + chr(14) +
chr(15) +
Ascii Data (16 ~ 255) + vbcrlf

There are no vbCRLFchars until the legit end of the line which
prevents the
Line Input# statement from prematurely ending the data line read. I
can't
seem to explain how the EOF falsely triggers after the first record is
read.

I have subsequently found a work-around but I would like to understand
why
this is failing.

Thanks,

~Steve
From: GS on
on 7/14/2010, Steve supposed :
> I am using the End Of File (EOF) function within a simple function to
> count records in a text file. I have never had problems with this
> function
> until I began using it to count records in text files which include
> lower
> value ascii characters in the source text files.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Public Function Count_Records(strFilePath As String) As Long
> 'Receive a path to a text file, and count the number of lines
> (records)
> 'If file doesn't exist, then function returns a value of ZERO
>
> Dim intFileNum As Integer
> Dim strCurLine As String
> Dim lngFileLen As Long
> Dim lngRecCtr As Long
> Dim blnPathIsInvalid as boolean
>
> On Error GoTo errHandler
>
> lngFileLen = FileLen(strFilePath)
>
> if blnPathIsInvalid then
> intFileNum = FreeFile()
> Open strFilePath For Input As intFileNum
>
> Do Until EOF(intFileNum)
> Line Input #intFileNum, strCurLine
> lngRecCtr = lngRecCtr + 1
> Loop
> Close intFileNum
> end if
>
> Count_Records = lngRecCtr
>
> Exit Function 'Bypass Error Handling
> errHandler:
> blnPathIsInvalid=True
> resume next
>
> End Function
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> What happens is after the first line of the text file is read via the
> Line Input# function, the EOF function suddenly returns a TRUE value
> and terminates the loop. Of course, there are many more lines of
> text in the source text file which need to be counted.
>
> The structure of the text lines contains regulated data such as ...
> Ascii Data (32 ~126) + chr(14) + Ascii Data(32~126) + chr(14) +
> chr(15) +
> Ascii Data (16 ~ 255) + vbcrlf
>
> There are no vbCRLFchars until the legit end of the line which
> prevents the
> Line Input# statement from prematurely ending the data line read. I
> can't
> seem to explain how the EOF falsely triggers after the first record is
> read.
>
> I have subsequently found a work-around but I would like to understand
> why
> this is failing.
>
> Thanks,
>
> ~Steve

I do something similar when storing data in text files using ADO
instead of EOF. Of course, the first line always contains field headers
so that makes it convenient to intialize the counter at zero and use
'MoveNext' to get the record count.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


From: Steve on
Sigh ... sorry wrong version. The actual version
has this line:

if Not(blnPathIsInvalid) then

On Jul 14, 1:01 pm, Steve <stevegd...(a)yahoo.com> wrote:
> I am using the End Of File (EOF) function within a simple function to
> count records in a text file.  I have never had problems with this
> function
> until I began using it to count records in text files which include
> lower
> value ascii characters in the source text files.
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Public Function Count_Records(strFilePath As String) As Long
> 'Receive a path to a text file, and count the number of lines
> (records)
> 'If file doesn't exist, then function returns a value of ZERO
>
> Dim intFileNum As Integer
> Dim strCurLine As String
> Dim lngFileLen As Long
> Dim lngRecCtr As Long
> Dim blnPathIsInvalid as boolean
>
> On Error GoTo errHandler
>
> lngFileLen = FileLen(strFilePath)
>
> if blnPathIsInvalid then
>    intFileNum = FreeFile()
>    Open strFilePath For Input As intFileNum
>
>    Do Until EOF(intFileNum)
>        Line Input #intFileNum, strCurLine
>        lngRecCtr = lngRecCtr + 1
>    Loop
>    Close intFileNum
> end if
>
> Count_Records = lngRecCtr
>
> Exit Function 'Bypass Error Handling
> errHandler:
>    blnPathIsInvalid=True
>    resume next
>
> End Function
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> What happens is after the first line of the text file is read via the
> Line Input# function, the EOF function suddenly returns a TRUE value
> and terminates the loop.  Of course, there are many more lines of
> text in the source text file which need to be counted.
>
> The structure of the text lines contains regulated data such as ...
> Ascii Data (32 ~126) + chr(14) + Ascii Data(32~126) + chr(14) +
> chr(15) +
> Ascii Data (16 ~ 255) + vbcrlf
>
> There are no vbCRLFchars until the legit end of the line which
> prevents the
> Line Input# statement from prematurely ending the data line read.  I
> can't
> seem to explain how the EOF falsely triggers after the first record is
> read.
>
> I have subsequently found a work-around but I would like to understand
> why
> this is failing.
>
> Thanks,
>
> ~Steve

From: Jim Mack on
Steve wrote:
> I am using the End Of File (EOF) function within a simple function
> to count records in a text file. I have never had problems with
> this function
> until I began using it to count records in text files which include
> lower
> value ascii characters in the source text files.

When reading 'As Input', the ASCII value (26) is reserved as an "end
of file" marker. If you encounter it in text, EOF() is True right
there. That is almost surely your issue.

--
Jim Mack
Twisted tees at http://www.cafepress.com/2050inc
"We sew confusion"

From: Steve on
On Jul 14, 1:19 pm, "Jim Mack" <no-uce-...(a)mdxi.com> wrote:
> Steve wrote:
> > I am using the End Of File (EOF) function within a simple function
> > to count records in a text file.  I have never had problems with
> > this function
> > until I began using it to count records in text files which include
> > lower
> > value ascii characters in the source text files.
>
> When reading 'As Input', the ASCII value (26) is reserved as an "end
> of file" marker. If you encounter it in text, EOF() is True right
> there. That is almost surely your issue.
>
> --
>    Jim Mack
>    Twisted tees athttp://www.cafepress.com/2050inc
>    "We sew confusion"

YEP! 23 characters into the first record and more sporadic beyond
that.

I never know that little nugget about the Open for Input mode!
I always 'assumed' the file was terminated with a NULL ascii(0)
value.

Thanks for the explanation Jim.

~Steve