Solved

Web Browser Control

Posted on 2002-05-29
5
203 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
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now