Object Reference Error.

Here is some code of mine:
Public PassedLine As String

Dim myValue As String = PassedLine
If myValue.IndexOf("Jason") > 0 Or myValue.IndexOf("Gaylord") > 0 Then
UpdateType = 1
Return
End If
UpdateType = 2I am getting an error on the IndexOf statement saying <b>Oject reference not set to an instance of an object</b>.

[388 byte] By [codefund.com] at [2007-12-16]
# 1
did you watch the value of "myValue" to see what it is, because it's probably because it's set to nothing.
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
To add to Erik's response: You have to remember that a String is an object (that is, a reference type) in .NET. THerefore, if PassedLine has never been initialized, it's going to be Nothing. Attempting to call a method of, or work with a property of, an object that's Nothing (or null, in C#), will give you this error.

In C#, FWIW, this code would have raised a warning at compile time, because you're attempting to use an uninitialized variable.

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
a lot of companies out there require that all strings be initialized to String.Empty to follow company standards
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
Sorry, should have mentioned that this is in the same MDI (yes I'm still working on it! :( ) application. The parent refrences the property and sets the value. I know the value works because I had a MessageBox test it. It comes across as a string.
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
Sorry, PassedLine must be set to Nothing in order for that error to occur, if that's really the only code involved. I was worried that there was an "order of operations" problem with the Or and > operators, but that wasn't it. I tried the code, and the only way I get that error is if PassedLine (and/or myValue is Nothing, but I don't see how that can happen unless PassedLine is Nothing). Can you add a Debug.WriteLine statement right before you attempt to work with myValue and really verify that it's not Nothing?
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 6
Actually, I got it working without the need for this. Thanks anyway. ;)
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 7
But we want to know -- why didn't the code work as it was? Was there a bug or something going on?
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 8
Well, I ended up using the same form and not using another form to bring in the values. I continued to receive an error with the form. If this need arises again, I'll let you know! ;)
codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...