Object not set to an instance (ERROR) INDEXOF in do loop?

J

jason

The below code fails with the above error on the indexof line (IF line
3/4 of the way down). I've used indexof before, but for some reason it
won't work in this loop. Thanks for any help or information.

Dim InString As String = ""
Dim LogInfo As New FileStream("d:\xxx\xx1.log",
fileShare.ReadWrite,FileAccess.Read)
Dim LogReadStream As New StreamReader(LogInfo)
Dim filecont as string
Do
filecont = LogReadStream.ReadLine()
'if line contains (ERRORING LINE BELOW)
if (filecont.indexof("Default.aspx") <> - 1)
Response.Write( filecont & "<br>" )
end if
Loop Until filecont = ""
LogReadStream.Close
 
K

Ken Cox [Microsoft MVP]

Hi Jason,

Is it possible that at some point filecont is Nothing and therefore you
don't exit the loop properly?

You are checking for an empty string (filecont = "") which may not indicate
the true end of the file.

Ken
 
P

Peter Rilling

The ReadX methods usually return a null/nothing if there is nothing left in
the stream. YOur end condition of filecont = "" may not exist.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top