My StreamReader object is null! --- please help!

A

almurph

Hi,

I'm opening a file into a Stream object and then pass this object
into a StreamReader. I then use a while loop and the ReadLine()
method to count the number of rows in this StreamReader.

I go to use the StreamReader again and notice there is nothing in it.
It would appear that the ReadLine() function blanks it!

Anyone know any way to overcome this? Any hints/suggestions/ideas/
alternatives/code-samples much much appreciated.

Thank you,
Al.


**** Some Sample Code ****

'For a given streamreader - counts the # rows
Private Function RowCount(ByVal sr As StreamReader) As Integer

Static Dim counter As Integer = 0

While Not (sr.ReadLine Is Nothing)

counter = counter + 1

End While

Return counter

End Function
 
F

Family Tree Mike

You need to rewind the stream after running through it once. You can reopen
the file (my preference) or use Stream.Seek(0, SeekOrigin.Begin).
 
A

almurph

You need to rewind the stream after running through it once.  You can reopen
the file (my preference) or use Stream.Seek(0, SeekOrigin.Begin).

















- Show quoted text -

Mike - thanks - works like a charm.
Cheers,
Al.
 

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

Top