-2

I am currently working on a webbrowser, and I cannot seem to make the favorites work properly. I know this is so easy, but could someone please help, I'm really stuck...

CODE:

Private Sub ToolStripButton8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
    Dim menuItem1 As New ToolStripMenuItem
    menuItem1.Text = (webbrowser.Url.ToString)
    ToolStripComboBox1.Items.Add(menuItem1)
    My.Settings.bookmarks.Add(webbrowser.Url.ToString)

End Sub

What am I doing wrong? Do I need a handler of some sort??? Thank you very much in advance!!

SierraOscar
  • 17,507
  • 6
  • 40
  • 68
  • 1
    Which line does the error occur on? What is the URL at the time of the error? Is `webbrowser` a public object? is it in scope? – SierraOscar Feb 21 '16 at 17:24
  • 1
    Thank you so much for replying! It occurs on the second line: menuItem1.Text = (webbrowser.Url.ToString) – Daniel Zykov Feb 21 '16 at 18:55
  • and the URL is any URL that im on, not one specifically, its whenever I press the "Add to favorites" button is when it happens. And since it is a tabbed webbrowser, there is no "WebBrowser1". – Daniel Zykov Feb 21 '16 at 19:07
  • At the start, use `If webbrowser Is Nothing Then MsgBox("No Object!")` my guess is that this is down to variable scope. – SierraOscar Feb 21 '16 at 19:09

1 Answers1

1

ITS FIXED! Thank you so much to everyone who helped, Macro Man gave a perfect solution:

If webbrowser Is Nothing Then MsgBox("No Object!")

and Bjørn-Roger Kringsjå gave a link where I learned a lot more about Nulling. This actually helped me in two other projects!:

What is a NullReferenceException, and how do I fix it?

Community
  • 1
  • 1