Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Object not set to an instance (ERROR) INDEXOF in do loop?

Reply
Thread Tools

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

 
 
jason@cyberpine.com
Guest
Posts: n/a
 
      06-06-2004
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
 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      06-06-2004
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


<> wrote in message
news: m...
> 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


 
Reply With Quote
 
 
 
 
Peter Rilling
Guest
Posts: n/a
 
      06-06-2004
The ReadX methods usually return a null/nothing if there is nothing left in
the stream. YOur end condition of filecont = "" may not exist.

<> wrote in message
news: m...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error:Object reference not set to an instance of an object. Suresh Kojhani ASP .Net 1 07-29-2004 12:10 PM
Error !Object reference not set to an instance of an object. !!! Help Parthiv Joshi ASP .Net 2 07-02-2004 10:28 AM
object reference not set to an instance of an object Tim ASP .Net 1 07-17-2003 04:21 PM
Object reference not set to an instance of an object. yysiow ASP .Net 1 07-12-2003 03:30 PM
Object reference not set to an instance of an object. Chris Fink ASP .Net 2 07-03-2003 06:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57