Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Web Browser Control

Hi There,

I am currently using the MS Internet Control (SHDOCVW.dll) in another app that I have, but it is reading HTML from a file on disk.  I have another use for this kind of control, but I want to be able to read the HTML in from a string variable (from a database) rather than from disk.

My question is:
1. Will this control handle this sort of operation? If so, how?
2. If the answer to 1 is no, then is there some other control (preferable one that is available to a basic VB installation) that will?

I want to be able to do something like this:

dim MyString as string
MyString = "<HTML><HEAD></HEAD><BODY>Hello World!</BODY></HTML>"

WebBrowserControl.Output = MyString

Any ideas?
1 Solution
I think if your aim is to show the html page in your Webbrowser, then show it directly like this

Assuming you have a webbrower1 on your form

Private Sub form_load()
Webbrowser1.navigate ""
End sub


If you are reading from your database, and the database coln is of string type, write this code in test.asp
Dim cn , rs, strTxt

Set cn=Server.CreateObject("Adodb.Connection")
Cn.open ".................." 'for opening connection

Set rs=Server.CreateObject("Adodb.recordset")
strTxt="select top 1 * from testTable"

rs.open strTxt,cn

'assuming this is the coln which stores the html tags
Response.write rs("strHTML")


and then make changes in the form load event of the form, like this

Private Sub Form_load()
 Webbrowser.Navigate ""
End sub


Hope this helps



In my opion the WebBrowser control is quite flawed, as it is not a simple task to put in dynamic content, even the "document" property is read-only.

However, you can do what you want to do by using the document property directly, and alling the "write" method on the document property, bascially as you would in DHTML code.

However, you must first ensure the document property contains valid IHTMLDocument interface. This is done by navigating to a blank page.

You can try the code below ( works for me at least! ):

WebBrowserControl.navigate ""
Do While WebBrowserControl.readyState <> READYSTATE_COMPLETE

To get the WebBrowser1 control, give Reference to Microsoft Internet controls in Project->Rferences, this will put the webbrowser control onto your toolbox.

I thought I missed that!

ok, maybe I'm missing the point here, but if you just want to display the contents of a string in a web browser control, why not just write that string to a temp file and open that?

strHTML = "<HTML><BODY>...</HTML>"
strFileName = GetTempDir & Timer & ".html"

Open strFileName For Output As 1
  Print #1, strHTML
Close 1

WebControl.Navigate strFileName

While WebControl.readyState <> READYSTATE_COMPLETE

Kill strFileName

finsterAuthor Commented:
hi mh2,

the only change I would make to your code is to have this in the 1st line:

WebBrowserControl.navigate "about:blank"

Because I will have 100's of users viewing dynamic content, and I don't want to waste time writing to disk, and the ensuring that it's not left behind, or overwritten by someone else, etc.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now