473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Nov 18 '05 #1
2 983
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
<ja***@cyberpine.com> wrote in message
news:ef*************************@posting.google.co 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


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

<ja***@cyberpine.com> wrote in message
news:ef*************************@posting.google.co 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

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: UGH | last post by:
I am looping the grid rows to set the values in the dropdownlists. I keep getting a run time error "Object reference not set to an instance of an object." The error occurs on line where it says...
3
by: Poewood | last post by:
Okay here are four classes for a pocket pc program: Input, fpositional, ComboBoxArray and TextBoxArray. The "input" class is the form. I use the fpositional class to handle most of the functions...
9
by: hina.pandya | last post by:
I m getting this error "Object reference not set to an instance of an object." when i run my application. i m trying to select a value from dropdownlist here is the code. Protected Sub...
10
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could...
3
by: jeroen | last post by:
hello, i'm having a problem with the following piece of code. i use it to read a string in an array, then search that string for ";;" symbols, then i read what comes after that to a variable,...
0
by: a | last post by:
I need to create an instance of a custom object 'School.Teacher' and use it in a Profile object. I'm developing a bad case of "Pretzel Logic" thinking about this. Filling the custom object ...
0
by: rlueneberg | last post by:
I am getting this error when trying to add typed object "Questions" to Arraylist QuestionsList: Object reference not set to an instance of an object. --> r.QuestionsList.Add(q); I tried...
1
by: kamleshsharmadts | last post by:
I am using Ajax with struts in web application. from jsp i am calling a function of ajax.js onclick of a button. code of that call function which calling from jsp given as below:- ...
3
by: suganya | last post by:
Hi Some professionals already has developed the project using menu. In my company, they have given me task to clear the error in that. It is a script file named as "menubarAPI4.js" which is kept...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.