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

Discussion in 'ASP .Net' started by jason@cyberpine.com, Jun 6, 2004.

  1. Guest

    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
     
    , Jun 6, 2004
    #1
    1. Advertising

  2. 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:...
    > 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
     
    Ken Cox [Microsoft MVP], Jun 6, 2004
    #2
    1. Advertising

  3. 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:...
    > 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
     
    Peter Rilling, Jun 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Parthiv Joshi
    Replies:
    2
    Views:
    717
    Kalyan
    Jul 2, 2004
  2. Suresh Kojhani
    Replies:
    1
    Views:
    2,423
    Anushi
    Jul 29, 2004
  3. Pedro Correia
    Replies:
    0
    Views:
    642
    Pedro Correia
    Jul 25, 2003
  4. Lauchlan M
    Replies:
    1
    Views:
    2,388
    S. Justin Gengo
    Aug 18, 2003
  5. Isaac Won
    Replies:
    9
    Views:
    444
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page