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

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
 
S

S. Justin Gengo

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
 
M

Mattias Sjögren

Sacha,

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



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top