Link to home
Create AccountLog in
Avatar of alanvranian
alanvranianFlag for United States of America

asked on

Error 91 on webbrowser

Using VB6 -

I have the webbrowser control on a form, everything is at the defaults except I change the size and make it visible just before I load the html into it.  The html is text that I get from mimeparsing email messages.  I've found the webbrowser control to be highly unreliable where sometimes it gives me an error code 91 - object variable not set when I load the text into it.  I've reviewed other postings on here extensively about this and tried a dozen different ways of loading the text, or looping till the readystate changes, etc etc and I can't get past this.

Oddly, I'll get it working just fine in the VB editor environment, and then when I compile it the exact same test data crashes in the compiled code.

If someone sees the error of my ways, that would be greatly appreciated... I've wasted days on this one issue now.

Here's the code:

(at this point in the routine, I have extracted the html code from the email message and stored it in the strTempHtml variable... then I simply do this)

        WebBrowser1.Left = 0
        WebBrowser1.Width = 10900
        WebBrowser1.Height = 5550
        WebBrowser1.Top = 1590
        WebBrowser1.Visible = True
        WebBrowser1.Document.Open ("")     ' (have also tried "about:blank" here)
        WebBrowser1.Document.Write strTempHtml

...and... thats it...  

This code opens my test email perfectly in the development environment, but as soon as I compile it, the compiled version gives me error 91 on the exact same data at the document.write statement.

I had wondered if maybe the problem was in the html I extracted from the email messages, but that appears to be OK.  I have samples you can download and look st, if you want to, at 

test1.html is the email that loads perfectly in the development environment, but gives me error 91 in the compiled version.  test2.html is code that never downloads the images in the develkopment environment and if I do a loop to give it doevents time, it never completes.  Both give me 91 in compiled.

Both of these load just fine in IE if you do a file open.

In trying to find a way to make this work, I've also tried all the statements below, in a variety of  sequences...

        'WebBrowser1.Navigate "about:blank"

        'WebBrowser1.Document.Open ("about:blank")

        'WebBrowser1.Document.body.innerHTML = strTempHtml
        'WebBrowser1.Document.documentElement.innerHTML = strTempHtml
        'Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE
        '    DoEvents

        'While WebBrowser1.ReadyState < 4
        '    DoEvents

        'Do Until WebBrowser1.Busy = False
        '    DoEvents

Avatar of PatG042800
Flag of United States of America image

I had the same error 91 when I used your code in a project in VB 6.0.

I know you said you tried the navigate method but I was able to get my project to run in design and compiled mode by using the following

WebBrowser1.Document.Open ("")
WebBrowser1.Navigate ("about:blank")

WebBrowser1.Document.Write strTempHtml
WebBrowser1.Navigate strTempHtml

Here is the complete code of the project that works on my computer
one form, one web broswer, three command buttons

Private Sub Command1_Click()
        strTempHtml = "C:\temp\test1.html"
        Me.WebBrowser1.Navigate strTempHtml
End Sub

Private Sub Command2_Click()
        strTempHtml = "C:\temp\test2.html"
        Me.WebBrowser1.Navigate strTempHtml
End Sub

Private Sub Command3_Click()
        strTempHtml = ""
        Me.WebBrowser1.Navigate strTempHtml
End Sub

Private Sub Form_Load()
        Me.WebBrowser1.Left = 10
        Me.WebBrowser1.Width = 5000
        Me.WebBrowser1.Height = 5000
        Me.WebBrowser1.Top = 720
        Me.WebBrowser1.Visible = True
        Me.WebBrowser1.Navigate ("about:blank")
End Sub


Now if that does not work tell me, do you have any 3rd party IE toolbars installed on your computer? If so which one(s).
Avatar of alanvranian


Not working for me...  when I use this approach, I get nothing in the browser.  If I add in a refresh afterwards, it says that basically the content cannot be found.  Ordinarily I use Codesmart, so thats a third party toolbar, but at your comment I turned that off and restarted VB and the behavior did not change.

This is some of the inconsistency I've been dealing with... works fine for you, not for me.  May well be my machine or my environment but without more info from the control, how do I know what to change?

Thanks for your effort... you did a lot of work on my behalf.
This is a bit more interesting now, however...  when I compile using your programming technique, I get this error: <img src=""> (hoping one can use inline images here), followed by -2147023673 Automation error where the control is basically saying it cannot find the thing I want to load.  Basically, it isn't working using the navigate method when the html is stored in a string.  I suppose I could write the html to a disk file and then open that and clean up afterwards, but thats pretty inefficient.  A possible workaround, however.
OK, look at Properties for C:\WINDOWS\system32\shdocvw.dll then Version tab \ File Version

I am running version 6.00.2900.2937 (xpsp_sp2_gdr.060623-0002)

Also are you using VB 6?

Did the code fail in design view or only after you compiled?
I'll have to wait till I get back to that development machine to give you the dll version... so that won't be till this evening.

Yes, it is VB6.  In design view, there is no error message .... just nothing displays in the control.  The error message I quoted only shows up in the compiled code.

6.00.2900.2937 (xpsp_sp2_gdr.060623-0002)

I'm running the exact same version of shdocvw.dll as you...
Avatar of PatG042800
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Yea, about half the time I wind up posting a question on here, it has no answer because I'm pretty thorough in troubleshooting before I resort to bothering other people.  If I'm here, its sort of a last resort...

I did test the compiled code on other machines in my lab... and the problem follows the code across a variety of versions of Windows and processors....

I haven't played with windbg, I'll do that... sounds like fun and who knows, maybe it will br the "Voila" moment...

Meanwhile, I've gone ahead and done an inelegant workaround where I'm writing the html to a temporary disk file, opening that in the browser and then killing the file when the form closes.  Its slower, but at least it works.  My quest for a better webbrowser control than microsofts also continues..

Thanks for your effort on this.. enjoy the points :)