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.

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

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

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

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 :)

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

Happy coding!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.