(2008 Visual Basic) I need help with an error in my code

125 pts.
Tags:
Debugging
innerText
System.NullReferenceException
Visual Basic
Visual Basic 2008
Visual Basic 2008 debugging
Web development
1.Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 2.For Each Link As HtmlElement In WebBrowser1.Document.Links 3.Dim strText As String = Link.InnerText 4.If strText.IndexOf("Heal") > 0 Then 5.Link.InvokeMember("Click") 6.Exit Sub 7.End If 8.Next 9.End Sub -here is my error i received in line 4. when trying to run my code. System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." what am i doing wrong? does anyone see anything that's not right? additional info: my code is set to click on a link button on a web page. the inner text changes after the word "heal" so i'm finding it difficult to find a solution to my code. I need some professional guidance. thank you for your time and help.

Answer Wiki

Thanks. We'll let you know when a new response is added.

It looks like Link.Innertext might be “Null” when you assign it to strText in one of the loops in the for/each.

You might try running the code in Visual Studio with a break point before and after the error and the assignment so you can watch the values.

This error is often because the code has used a reference to a object before it is assigned or initialized. I see where you’ve initialized it, but you might also try breaking it into two lines.

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TryingHard
    [...] >> Visual Basic 2008: Need help with an error in my code [...]
    0 pointsBadges:
    report
  • SRond
    Check out this book except, Murach's VB 2008. It has some good tips on Visual Basic 2008 and coding
    95 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following