Solved

Web Browser Control

Posted on 2002-05-29
5
262 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:finster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7043831
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 "1.1.1.127/project/test.htm"
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")
rs.CursorLocation=3
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 "1.1.1.127/project.testAsp.Asp"
End sub

'----------------------------------

Hope this helps

-priya

0
 
LVL 3

Accepted Solution

by:
mh2 earned 50 total points
ID: 7043855
Hi,

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
   DoEvents
Loop
WebBrowserControl.Document.write(MyString)

Thankx,
Mark
0
 
LVL 2

Expert Comment

by:priya_pbk
ID: 7043862
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!

-priya
0
 
LVL 1

Expert Comment

by:pit__
ID: 7045533
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
  DoEvents
Wend

Kill strFileName

0
 

Author Comment

by:finster
ID: 7045711
hi mh2,

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

WebBrowserControl.navigate "about:blank"


pit:
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question