Solved

Web Browser Control

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB error "Type mismatch" 2 55
Best way to parse out a json string in VB6? 10 171
Using "ScreenUpdating" 6 65
MS Date Picker 64 bit 32 bit issue 12 55
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

810 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