Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Object variable or with block variable not set error using Webbrowser control

Hi

I have used webbrowser control to navigate URL in VB. But in some situation, i got the error like

"Error Number : 91 Object variable or with block variable not set"

But i really don't know where i have made the mistake. Below is my code. I put the messages in between statements. But i can't catch which line i can get the error and how to solve.

Can anyone suggest me to come out in this issue.

*******
Dim g_oIE as SHDocVw.InternetExplorer
Set g_oIE = New SHDocVw.InternetExplorer

g_oIE.Navigate (strHTMLPath)

Do While g_oIE.Busy
DoEvents
Loop

'Seperate data and header
Dim strHeader As String
Dim strFotter As String
Dim intHPos As Integer
Dim st As TextStream

'Get the data
strData = g_oIE.Document.body.innerHTML
Pos = InStr(strData, "HLast")

' Check whether the URL is correct (no junks Present)
If Pos = 0 Then

frmVerses.AddMessage "IE Page cannot be Found"
' Creating error file by converting .trg into .vre
Call CreateErrorFile(m_strFullTrgFileName, "IE page cannot be found")
Exit Sub
End If
Set g_oIE = Nothing

*******
[1516 byte] By [Hariharan] at [2007-11-11 10:01:56]
# 1 Re: Object variable or with block variable not set error using Webbrowser control
I suggest that, rather than using a DoEvents loop to wait for the page to load, you omit the loop and move everything that follows it to the WebBrowser's NavigateComplete event, which fires when the page has finished loading. You'll have to declare the browser at the form/class level and use WithEvents:

Private WithEvents g_oIE As InternetExplorer

If the problem persists after you do that, try checking that the browser's Document property is Not Nothing before you try to use it:

If Not g_oIE.Document Is Nothing Then
' Get the data
strData = g_oIE.Document.body.innerHTML
' etc.
Phil Weber at 2007-11-11 17:23:19 >
# 2 Re: Object variable or with block variable not set error using Webbrowser control
Hi phil

I got ur response. So you are telling whenever it will take time to load the page, it will come right? Suppose i am creating that variable withEvents i can get that event right?

If the problem persists again i have to check if that variable is not nothing right?
Hariharan at 2007-11-11 17:24:19 >
# 3 Re: Object variable or with block variable not set error using Webbrowser control
After declaring the variable into form level, shall i need to create a new instance for that.

Set g_oIE = new sch... Internetexplorer

Kindly update me in this regard

:confused:
Hariharan at 2007-11-11 17:25:30 >