[RESOLVED] [2005] How to get around error 91
Hey folks, I've been working on adding a couple of search engines to my IE clone, but everytime i run the program, i always get this msg
Quote:
Object reference not set to an instance of an object. Error Number: 91
the documentation on .GetElementById and .InvokeMember is sketchy at best, i've tried msdn, this forum, google, and all the other tricks i know, can anyone help?
Here's my code
VB Code:
Private Sub doSearchQuery()
Dim google As String = "http://www.google.com/search?hl=en&q=" 'Google's search engine string
Dim yahoo As String = "http://search.yahoo.com/search;_ylt=A0geuoxASo1FZw4AFj2l87UF?ei=UTF-8&fr=sfp&p=" 'Yahoo's search engine string
Dim googleId As String = "btnG"
Dim Click As String = "click"
'Dim helement As New HtmlElement
Try
If lbSearchSelect = "Google" Then
wbPKMN.Navigate(google & SearchString) 'Navigate to google
wbPKMN.Document.GetElementById("btnG").InvokeMember(Click)
Else
wbPKMN.Navigate(yahoo & SearchString) 'navigate to yahoo
wbPKMN.Document.GetElementById("yschqcon").InvokeMember(Click)
End If
Catch ex As Exception
nwWriteLogMsg(ex.Message, ".\nwpps2k6err.log", ex.StackTrace, ex.TargetSite.ToString, ex.Source, ex.HelpLink)
With frmException
.lblTitle.Text = "UriFormatException"
.txtDesc.Text = ex.Message & " Error Number: " & Err.Number
.lblSource.Text = ex.Source
.lblTargetMethod.Text = ex.TargetSite.ToString
.ctbSTrace.Text = ex.StackTrace
.ShowDialog(Me)
End With
End Try
LbSearch.Hide()
End Sub
The funny thing about this is, it works, even though it's throwing that error everytime. Just wonder if there's a way around it
Redmo
Re: [2005] How to get around error 91
Re: [2005] How to get around error 91
i'm already running a try, catch, i'll edit the code above to show the full routine, might give ye a better idea of what's goin on :D
Redmo
Re: [2005] How to get around error 91
I think the problem is that you are not giving parameters to the click event... (such as sender and mousevents as e), to prevent these errors, you should probably move your click event code to a sub and call it instead of provoking a click....
:wave:
Re: [2005] How to get around error 91
i'm not sure i fully understand, but when the user enters their query into the searchbox, both the keypress, and the go button fire of the doSearchQuery routine(the 1 above). I have nothing else in either of the other routines, except a check to make sure a search engine's selected.. :(
Redmo
Re: [2005] How to get around error 91
Quote:
Originally Posted by redmo
Hey folks, I've been working on adding a couple of search engines to my IE clone, but everytime i run the program, i always get this msg
the documentation on .GetElementById and .InvokeMember is sketchy at best, i've tried msdn, this forum, google, and all the other tricks i know, can anyone help?
Here's my code
VB Code:
Private Sub doSearchQuery()
Dim google As String = "http://www.google.com/search?hl=en&q=" 'Google's search engine string
Dim yahoo As String = "http://search.yahoo.com/search;_ylt=A0geuoxASo1FZw4AFj2l87UF?ei=UTF-8&fr=sfp&p=" 'Yahoo's search engine string
Dim googleId As String = "btnG"
Dim Click As String = "click"
'Dim helement As New HtmlElement
Try
If lbSearchSelect = "Google" Then
wbPKMN.Navigate(google & SearchString) 'Navigate to google
wbPKMN.Document.GetElementById("btnG").InvokeMember(Click)
Else
wbPKMN.Navigate(yahoo & SearchString) 'navigate to yahoo
wbPKMN.Document.GetElementById("yschqcon").InvokeMember(Click)
End If
Catch ex As Exception
nwWriteLogMsg(ex.Message, ".\nwpps2k6err.log", ex.StackTrace, ex.TargetSite.ToString, ex.Source, ex.HelpLink)
With frmException
.lblTitle.Text = "UriFormatException"
.txtDesc.Text = ex.Message & " Error Number: " & Err.Number
.lblSource.Text = ex.Source
.lblTargetMethod.Text = ex.TargetSite.ToString
.ctbSTrace.Text = ex.StackTrace
.ShowDialog(Me)
End With
End Try
LbSearch.Hide()
End Sub
The funny thing about this is, it works, even though it's throwing that error everytime. Just wonder if there's a way around it
Redmo
Hi,
You could try something like this;
VB Code:
Dim Google As string = Process.Start("www.google.com")
Hope it helps,
sparrow1
Re: [2005] How to get around error 91
I kinda solved the problem by just not showing the user the exception msg generated. I know this is wrong, and i'm going to burn in hell, but what the hell, it works. I already know, HtmlElement is very poorly documented, anyone else know how to use it properly...
btw, system diagnostics.process, cannot be converted into a string.
Redmo