954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Error: Object reference not set to an instance of an object.

Hi,

I'm comparing String with array of Strings and I got this error

Object reference not set to an instance of an object.

This is my code:

For Each Str As String In Word
                    If Str.Contains(w1) = False Then

                        MsgBox(w1 & _
                          Str.IndexOf(w1))
                        out += 1
                    End If
                Next


The error in this line:

If Str.Contains(w1) = False Then


Any one have an idea??

thanks in advance.

Maha Sh.
Light Poster
35 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

What is wl ? It is looking for an object to be there, but is not finding one.

bklynman01
Junior Poster in Training
94 posts since Oct 2010
Reputation Points: 12
Solved Threads: 6
 

w1 is a string and I know it's looking for an object and not finding it but how I can fix it???:(

Maha Sh.
Light Poster
35 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Hi again
I think the cause of my error is that i set the Strings of the array in a sub class and call the array in another sub class

Maha Sh.
Light Poster
35 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

I solved my error :icon_cheesygrin:

The problem was I left the array empty in the public class because it should be filled by the user ,and when the user click on the help button which will search on the array while it's empty the error occur. So I just filled the array in the public class .

:$ I am just a beginner in VB


Thanks bklynman01 for your reply it was helpful :)

Maha Sh.
Light Poster
35 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

I'm glad you were able to solve it. I'm sorry I didn't get back sooner...

Happy coding!

bklynman01
Junior Poster in Training
94 posts since Oct 2010
Reputation Points: 12
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You