473,403 Members | 2,293 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,403 software developers and data experts.

object refrence not set to an instance of an object ??

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, witch goes to a text box. but every time
i run the subroutine, i get an "Object reference not set to an instance of an
object." error at the time it reaches "start = line.IndexOf(";;")"

also, wenn i set a breakpoint to debug it, de breakpoint red point's get a
question mark in it(meaning the code isn't avalible?). what's that all about ?

Code:
Dim line, start2 As String
Dim start As Integer
Dim counter As Integer = 0

If comments.Count = 0 Then
Exit Function
End If

While counter < countedcomments
counter += 1
line = comments(counter)
If line.StartsWith(fotos(positionarray)) Then
Exit While
End If
End While

start = line.IndexOf(";;")

If Not start = -1 Then
txtbijschrift.Text = ""
Exit Function
End If
start2 = Mid(line, start)
txtbijschrift.Text = start2

thanks for the help :)
jeroen
Nov 21 '05 #1
3 1209
Jeroen,

Your string in this code Is Nothing

The string is a strange thing (it is a value), however it is not set to
Something by default. And therefore your string is Nothing and not empty.

I would use a more modern code by the way and use the indexed for, your code
becomes more readable and goes faster (although the last is probably not
that important here).

I hope this helps,

Cor
Nov 21 '05 #2
"jeroen" <je****@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
:
: 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, witch goes to a text
: box. but every time i run the subroutine, i get an "Object reference
: not set to an instance of an object." error at the time it reaches
: "start = line.IndexOf(";;")"
:
: also, wenn i set a breakpoint to debug it, de breakpoint red point's
: get a question mark in it(meaning the code isn't avalible?). what's
: that all about ?
:
: Code:
: Dim line, start2 As String
: Dim start As Integer
: Dim counter As Integer = 0
:
: If comments.Count = 0 Then
: Exit Function
: End If
:
: While counter < countedcomments
: counter += 1
: line = comments(counter)
: If line.StartsWith(fotos(positionarray)) Then
: Exit While
: End If
: End While
:
: start = line.IndexOf(";;")
:
: If Not start = -1 Then
: txtbijschrift.Text = ""
: Exit Function
: End If
: start2 = Mid(line, start)
: txtbijschrift.Text = start2
:
: thanks for the help :)
: jeroen
This error is indicating that the 'line' object is a null reference
(Nothing). You did not instantiate your line object when you declared it
and, evidently, it is not being assigned inside your while loop. My
guess is this is because 'counter' starts out as greater than
'countedcomments'. In that case, the statement 'line = comments(counter)
is never beening reached. If so, then when you attempt to access the
indexOf function of the string class, the code objects because 'line' is
uninstantiated (it remains a null value).
Try instantiating the 'line' variable when you declare it (Dim line As
String = "") or check to ensure the variable is referencing a live
object prior to the state where your error is occuring. For example:
If line Is Nothing Then
'add whatever logic you feel
'is appropriate here

Else
start = line.IndexOf(";;")

If Not start = -1 Then
txtbijschrift.Text = ""
Exit Function
End If
start2 = Mid(line, start)
txtbijschrift.Text = start2

End If

HTH

Ralf
Nov 21 '05 #3
thanks, i rewrote it a little. and it works now :)
"_AnonCoward" wrote:
"jeroen" <je****@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
:
: 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, witch goes to a text
: box. but every time i run the subroutine, i get an "Object reference
: not set to an instance of an object." error at the time it reaches
: "start = line.IndexOf(";;")"
:
: also, wenn i set a breakpoint to debug it, de breakpoint red point's
: get a question mark in it(meaning the code isn't avalible?). what's
: that all about ?
:
: Code:
: Dim line, start2 As String
: Dim start As Integer
: Dim counter As Integer = 0
:
: If comments.Count = 0 Then
: Exit Function
: End If
:
: While counter < countedcomments
: counter += 1
: line = comments(counter)
: If line.StartsWith(fotos(positionarray)) Then
: Exit While
: End If
: End While
:
: start = line.IndexOf(";;")
:
: If Not start = -1 Then
: txtbijschrift.Text = ""
: Exit Function
: End If
: start2 = Mid(line, start)
: txtbijschrift.Text = start2
:
: thanks for the help :)
: jeroen
This error is indicating that the 'line' object is a null reference
(Nothing). You did not instantiate your line object when you declared it
and, evidently, it is not being assigned inside your while loop. My
guess is this is because 'counter' starts out as greater than
'countedcomments'. In that case, the statement 'line = comments(counter)
is never beening reached. If so, then when you attempt to access the
indexOf function of the string class, the code objects because 'line' is
uninstantiated (it remains a null value).
Try instantiating the 'line' variable when you declare it (Dim line As
String = "") or check to ensure the variable is referencing a live
object prior to the state where your error is occuring. For example:
If line Is Nothing Then
'add whatever logic you feel
'is appropriate here

Else
start = line.IndexOf(";;")

If Not start = -1 Then
txtbijschrift.Text = ""
Exit Function
End If
start2 = Mid(line, start)
txtbijschrift.Text = start2

End If

HTH

Ralf

Nov 21 '05 #4

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

Similar topics

6
by: Hameed Khan | last post by:
hi, i was reading library refrence manual. there i found object() function. they says in library refrence that "Return a new featureless object. object() is a base for all new style classes. It...
7
by: Nick Zdunic | last post by:
I have a remotable object running in my host application. The host starts up and creates the object. Within a method to start the remote object doing its thing it creates an object. ...
12
by: Olumide | last post by:
I'm studying Nigel Chapman's Late Night Guide to C++ which I think is an absolutely fantastic book; however on page 175 (topic: operator overlaoding), there the following code snippet: inline...
14
by: Samuel R. Neff | last post by:
Why would you cast two strings to objects to compare them? I saw code in an MS sample on MSDN and don't get it. if ( (object)name == (object)attr.name ) { both "name" and "attr.name" are...
3
by: Rudy | last post by:
Hello All! I get this error at this line Line 368: Len(e.Item.Cells(5).Text) - 1) Line 369: txtQty.Text = e.Item.Cells(5).Text ****Line 370: chkEbay.Checked =...
1
by: John Rugo | last post by:
Hi All, I would like to know how to set an object from a string provided? Here is the situation: I have a listview that holds the names of ListView Objects on different forms. I want to set...
3
by: Nagesh | last post by:
hi, I have seen the winvnc(tightvnc server) source code in this I seen that class member funtions are calling without instantiating the object i.e. like vncService::ShowDefaultProperties() where...
3
by: red_ghost | last post by:
in my home.aspx page I have a simple login set. when you hit the button it redirects. Here is the code: Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)...
3
by: preitymathur0422 | last post by:
I m working on a MDI application. Here on the parent form I had two variables declared as public int curUserID = 0, ViewUserID = 1; the form is inherited by the "Form" class. I m using these...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.