?
Solved

again: visual basic webbrowser control and framed pages

Posted on 2003-03-17
12
Medium Priority
?
253 Views
Last Modified: 2013-11-25
Well, I 've got the following problem:
I need to get the calling frame of a frameset in webbrowser control to evaluate users input (important topics are HTMLForm-Elements, Links, etc).
This function needs to work with unknown framesets, because the pages change dynamic.
To realize this, I have created an instance of webbrowser control which creates an instance of a class called EventListener.

Here are some important parts of the code:

Dim Listener() As New EventListener
Dim listen As Boolean               'will be true, after the Listener is instantiated
Dim EventCount As Long
Public WithEvents htdoc As HTMLDocument
Dim htdoc2 As HTMLDocument
Dim eventindex As Long

Private Sub Recorder_DownloadComplete()
    'After the Browser receives a DocumentComplete Event, it the Listener is reinstantiated.
    Set htdoc = Recordbrowser.Recordbrowser.Document
       
    ReDim Listener(htdoc.frames.length)
    Listener(0).InitEvent htdoc
   
    For EventCount = 0 To htdoc.frames.length - 1
'    Debug.Print htdoc.activeElement.tagName
        Set htdoc2 = htdoc.frames(EventCount).Document
        Listener(EventCount + 1).InitEvent htdoc.frames(EventCount).Document
        EventCount = EventCount + 1
        If EventCount > 15 Then Exit For
    Next EventCount
    listen = True

 
End Sub

Public Sub Recorder_BeforeNavigate(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Cancel As Boolean)
Dim i%
     For i = 1 To htdoc.frames.length - 1
        If htdoc = Listener(i).getDoc Then Listener(i).checkEvent
       
        'Listener(i).getDoc code:
        '
        'Public Function getDoc() As HTMLDocument
        '    Set getDoc = htmDoc
        'End Function
        'Listener(i).checkEvent code:
        'Public Sub checkEvent()
        'If UCase(htmDoc.activeElement.tagName) = "A" Then
        '  html_link_onclick
        ' ElseIf UCase(htmDoc.activeElement.tagName) = "INPUT" Then
        '  html_form_onsubmit htmDoc.activeElement.tagName
        ' Else
        '     Debug.Print htmDoc.activeElement.tagName
        '     Debug.Print htmDoc.activeElement.outerHTML
        'End If
        'End Sub
     Next i

End Sub
0
Comment
Question by:tillix
[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
12 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8152975
Recorder_DownloadComplete is the name of your webbrowser control?
If so, you have a problem:
Downloadcomplete event is raised for EVERY frame in the document.
You need to wait until all frames are downloaded. To do so you need a simple if statement
sub Recorder_DownloadComplete(....)
if (pDisp is recorder.object) then
   ' your actual code goes here.
en if
end sub
0
 

Author Comment

by:tillix
ID: 8155175
- Recorder is instantiated as shdocvwctl.webbrowser_v1
- I think you're right with documentComplete Event (might be that I have turned it round with downloadComplete; I can't answer this at the moment, because I'm at home), but my main problem is that I need access to form-elements in framed pages and have to realize the name, type and value of the element.
E.g. The user fills some form-elements, checks a radio button and finally clicks on a submit button.
greeting
tillix
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8155371
Ups!, i meant, documentcomplete event and NOT downloadcomplete event:

sub Recorder_DocumentComplete(....)
if (pDisp is recorder.object) then
  ' your actual code goes here.
en if
end sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:tillix
ID: 8155620
ok.
but how can I access the form values through the DOM? I have no problems without frames, but with.
0
 

Author Comment

by:tillix
ID: 8155719
ok.
but how can I access the form values through the DOM? I have no problems without frames, but with.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8158850
i think some like that:
You need an array of HTMLDocument to hold each frame (which is a document itself)

dim IEDocs() as HTMLDocument

in the main DocumentComplete event:

Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
    Dim i As Integer
    For i = 1 To WB1.Document.frames.length
        ReDim Preserve IEDocs(i)
        Set IEDocs(i) = WB1.Document.frames(i).Document
    Next
End If

End Sub


After that, you have access to every single document in the array and use the DOM to locate objects in each of them.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8159304
Please, change to this (it is better ;)

Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
    Dim i As Integer
    For i = 0 To WB1.Document.frames.length - 1
        ReDim Preserve IEDocs(i)
        Set IEDocs(i) = WB1.Document.frames(i).Document
    Next
End If

End Sub
0
 

Author Comment

by:tillix
ID: 8179791
Sorry for the late comment.
Well, finally I did it with a method called "recurse Frames". The original version of this method can be found at http://www.microsoft.com/mind/0898/dom.asp.
It shows how to walk through the frames. At least I have to modify this method a bit instead of the fillTree call I used my own method, which checks for the values of a htmlform.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8180792
That page is already known. What i don't understand is the diference between

...
...
for each frame in doc. frames
....
....
posted at that site with

for i= 0 to doc. frames.length-1

I know that one use an object and other and index but, besides that.. what?
0
 

Expert Comment

by:CleanupPing
ID: 8532202
Hi tillix,
This old question (QID 20553330) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8956522
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

-->PAQ - with points refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

GPrentice00
EE Cleanup Volunteer
0
 

Accepted Solution

by:
PashaMod earned 0 total points
ID: 9012101
Per recommendation,

PashaMod
CS Moderator
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

764 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