50 pts.
0
Q:
(2008 Visual Basic) I need help with an error in my code
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.
ASKED: Nov 29 2008  4:51 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
5320 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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.
Last Answered: Mar 27 2009  2:36 PM GMT by Jlees   5320 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

IT Knowledge Exchange Community Update for 12/02/08 - ITKE Community Blog   0 pts.  |   Dec 2 2008  6:00PM GMT

[...] >> Visual Basic 2008: Need help with an error in my code [...]

 
0