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

  • Thread starter Thread starter almurph
  • Start date Start date
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
 
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).
 
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.
 
Back
Top