How to check for EOF (End of file) when using StreamReader to parse text file

  • Thread starter Thread starter Sacha Korell
  • Start date Start date
S

Sacha Korell

How would I check for an end of file when parsing a text file using the
StreamReader object?

I would like to do something like this:

'********************************
Dim objStreamReader As StreamReader
Dim strReqLine As String

objStreamReader = File.OpenText("data.txt")

While NOT objStreamReader.EOF

strReqLine = objStreamReader.ReadLine

'* Code to parse the line for data

End While
'********************************

Except the StreamReader object doesn't seem to have an EOF property. Are
there any work-arounds?

Thanks,

Sacha
 
Sacha,

Just use:

While StreamReader.Read

End While

It will stop when it hits EOF.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
 
Sacha,

strReqLine = objStreamReader.ReadLine()
While Not strReqLine Is Nothing
'* Code to parse the line for data
strReqLine = objStreamReader.ReadLine()
End While



Mattias
 
Back
Top