Solved

WebBrowser Ctrl - populating vars in HTML

Posted on 2001-08-07
12
211 Views
Last Modified: 2007-11-27
In a VB EXE project ... how do you bind or populate variables in html pages while using the WebBrowser control to display the html?

I'm aware of using client side or server side variables in ASP pages but I don't want to develop a DHTML project nor an IIS application.  I want to use the WebBrowser to display local html files, but I need to be able to replace some of the text with variable information..

It seems to me that pre-processing the html document prior to sending it to the WebBrowser in overkill or a "brute force" method.  That is, I could read through the html, looking for variables (eg.  <!LastName>  ) and replace that with the variable text before sending it to the WebBrowser control.

Actually, that's just a one-way communication anyway.  I guess I'm also looking for getting info back from the html page, perhaps the text in a text box, or the value of a radio button.  So how would you reference named objects in the document?... something like....

lsLastName = WebBrowser1.Document.formName.textareaName.value






0
Comment
Question by:PatOBrien
[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
  • 3
  • 3
  • 2
  • +3
12 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6360841
you can try this:

WebBrowser.Document.Body.innerHTML = Replace(WebBrowser.Document.Body.innerHTML, "<MyTag>", "VariableInfo")

hope this helps!
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6360852
>>something like....
>>lsLastName = WebBrowser1.Document.formName.textareaName.value

yes, or:
var = WebBrowser1.Document.all("elementName").AnyProperty

your options for building the html are:
1) you can build the html on the fly
2) do search and replace
3) set values for named elements directly

for option 3, you can set the value for a textbox, for example, by using the same syntax as above, e.g.:

WebBrowser1.Document.all("txtName").value = "Some text"

where the html for that textbox may look like:

<input type="text" name="txtName">
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6360985
all webbrowser questions should be labeled:
For AzraSound ;)

0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 28

Expert Comment

by:AzraSound
ID: 6361181
LOL
0
 
LVL 5

Author Comment

by:PatOBrien
ID: 6361490
Well, I couldn't get the method suggested by JonFish85 to work.

Using the #3 method suggested by AzraSound produced the following:

in my html document I added:

<span id="EEName">x</span>

where I wanted the name info to appear.

in my project, in a command_click event I had the navigate command and the innerText command as follows:

    WebBrowser1.Navigate2 App.Path & "\html\test.html"
    WebBrowser1.Document.All("EEName").innerText = "Elvis"
   
I got an error on the second line.... error 91 Object variable or With Block Variable not set.

However, when I went into debug mode I could step [F8] through the line and the resulting browser display showed the "Elvis" name right where I wanted it!!

I tried putting in a loop that waited while WebBrowerser1.busy was true.  That didn't help.  In fact I tried a 3 second delay between the two lines.  That didn't help either.


Finnaly, I moved the #2 line above to the WebBrowser1.NavigateComplete2 event

I had to add some code to check that the LocationName was the same as the html file that I was loading, but it seemed to work.
   
Next I'll try this with some text fields and radio buttons.
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6361506
try this:

WebBrowser1.Navigate2 App.Path & "\html\test.html"
Do Until WebBrowser1.Busy = False
Doevents
Loop
WebBrowser1.Document.All("EEName").innerText = "Elvis"

hope this helps!
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6361509
sorry, I didnt read thouroughly :-/
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6361608
Listening...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6361615
I think that if you don't want "brute-force" approach, first need to show the document and on the documentcomplete event do the changes.
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 6361730
for the "wait" loop, try:

WebBrowser.Navigate strSomewhere
Do While WebBrowser.ReadyState <> READYSTATE_COMPLETE
   DoEvents
Loop

or, you can set this value in the WebBrowser's DocumentComplete event.  you can set some boolean flag indicating whether to set the value in the DocumentComplete event or not, e.g.,

Private Sub WebBrowser_DocumentComplete(...)
   If blnSetValue = True Then
      WebBrowser.Document.all("EEName").innertext = strNewValue
   End If
End Sub
0
 
LVL 28

Expert Comment

by:Ark
ID: 6361866
If WebBrowser1.ReadyState > READYSTATE_COMPLETE Then Debug.Print "TOTALLY COMPLETE! :)"

Cheers
0
 
LVL 5

Author Comment

by:PatOBrien
ID: 6363732
Thanks.  You pointed me in the right direction.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 95
MS Date Picker 64 bit 32 bit issue 12 72
SQL VB connection works in one PC and doesn't in another 15 79
RUNRMTCMD from AS/400 13 122
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…
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.
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…
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…

739 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