0

My goal here is to create a web browser that has a tab system in VB. Since I cannot explicitly name every single new tab the user will use, I have to make more generalized callings. Here's the conflicting code (my btnGo):

Dim thisBrowser As newWebBrowser = Me.tabBrowser.SelectedTab.Tag
    If txtAdressSearch.Text.Contains(".com") Or txtAdressSearch.Text.Contains(".net") Or txtAdressSearch.Text.Contains(".gov") Or txtAdressSearch.Text.Contains(".edu") Or txtAdressSearch.Text.Contains(".org") Then 'More to be checked for
        thisBrowser.Navigate(txtAdressSearch.Text)
    Else
        thisBrowser.Navigate("https://www.google.com/search?sourceid=chrome-psyapi2&rlz=1C1ASAA_enUS445&ion=1&espv=2&ie=UTF-8&q=" + txtAdressSearch.Text)
    End If

And here's the newWebBrowser code:

Public Class newWebBrowser
Inherits WebBrowser

Private Sub webBrowserComplete() Handles Me.DocumentCompleted
    Dim newTab As TabPage = frmBrowser.Tag()
    Dim frmSK As New frmBrowser
    Dim hi As String
    newTab.Text = Me.DocumentTitle
    frmSK.txtAdressSearch.Text = Me.Url.ToString

End Sub

End Class

Any time I enter something into txtAdressSearch, Visual Studio raises a NullRefrenceException and highlights thisBrowser.Navigate(txtAdressSearch.Text). As a side note, it says "Object reference not set to an instance of an object."

Anyone know whats the problem here? Thank you.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
said
  • 474
  • 4
  • 8
  • 18
  • @DourHighArch, ah, sorry. Just saw the conflicting tags. Its VBA. – said Feb 03 '15 at 02:23
  • Your browser reference is dependent on there being a Tab selected somewhere and the Tag prop containing a valid object reference. (and seems more like VB.NET than VBA code) – Ňɏssa Pøngjǣrdenlarp Feb 03 '15 at 02:24
  • @Plutonix, there was always a tab selected. As for the Tag property, I am not 100% sure if it does have an object reference. How would I check this? – said Feb 03 '15 at 02:31
  • It almost certainly doesnt have a valid object or you would not get the error. In NET just hold the mouse over `Tag` or `thisBrowser` after the assignment. See also [NullReference Exception in Visual Basic](http://stackoverflow.com/a/26761773/1070452) – Ňɏssa Pøngjǣrdenlarp Feb 03 '15 at 02:36
  • @Plutonix, when I hover over `thisBrowser`, it says nothing, which is probably the cause of this issue. How would I go about setting the Tag to what I want it to be? – said Feb 03 '15 at 02:40
  • Nothing in VB means null, so when you do Nothing.Navigate(..) You get a null reference exception. You should check why thisBrowser doesn't get initialized properly – Y.S Feb 03 '15 at 06:04
  • @Y.S, thanks, I solved it. I forgot to put in a very big chunk of what I needed to put, so tags weren't lining up correctly with what they were supposed to be. Either way, thanks for taking time to try to help. – said Feb 03 '15 at 18:28

1 Answers1

0

After debugging for more than an hour, I looked over my code and saw I was missing a big part of it. I wrote it all in and it worked fine. The issue was the tags weren't being defined correctly (and in some cases, not at all) so .Tag was returning Nothing.

Thanks to all who helped.

said
  • 474
  • 4
  • 8
  • 18