Hi Doug,
I'm just wondering whether you could do this and encapsulate the whole thing
in an appropriate try/catch block. EOF is "end of file" -- perhaps this is
what you really want to be testing for...
while not EOF(1)
your code...
loop
I'm a newbie at VB.NET, but it might be worth a try.
Sincerely,
Davis Bennett
P.S. If you try this, let me know how you make out
"Doug Gifford" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> WROX "Beginning VB.Net" 2nd Edition
>
> Using this code from Chapter 11 Page 472:
> Do
> Try
> ' Read a line from the file...
> currentLine = myReader.ReadLine
> lineCounter = lineCounter + 1
> Catch e As EndOfStreamException
> ' Display the message...
> MessageBox.Show(e.Message)
> ' Exit the Do loop...
> Exit Do
> Finally
> ' Concatenate the data to the strData
> variable...
> currentData = currentData & currentLine &
vbCrLf
> End Try
> Loop While currentLine <> Nothing
>
> The text file I am reading has blank lines in it.
> Sample:
>
> Line one <CrLf>
> Line two <CrLf>
> <CrLf>
> Line Four <CrLf>
> Line Five <CrLf>
> Line Six <CrLf>
>
> When the code reaches Line Four it exit the loop because
> currentLine = Nothing.
>
> I want to read all the lines (one at a time) and exit the loop
> when I have reached the end of the file. I still want to read past the
blank
> lines.
>
> If I use a straight loop without the "While currentLine <>
> Nothing" the "Catch e As EndOfStreamException" does not catch the end of
> stream exception and enters an infinite loop!
> How can I read the stream, one line at at time, and process
> "ALL" the lines in the file?
>
>
>
>
>
>
|