[quoted text, click to view] "jeroen" <jeroen@discussions.microsoft.com> wrote in message
news:C35A2670-C94F-4582-A202-AF6303429D9D@microsoft.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