Solved

Using WebBrowser Control within Class Modules

Posted on 2001-06-29
19
268 Views
Last Modified: 2013-11-26
I'm creating an ActiveX Dll project that has 'frmWebBrowser' which has a WebBrowser1 control in it.  I also have a 'clsWidget'.  For each instance of 'clsWidget', I would like to have a 'thisWebBrowser as WebBrowser' property with events.  Here's what I have so far:

From clsWidget:

Private WithEvents thisWebBrowser As frmWebBrowser

Public Function Connect() As Long
Dim newIndex as Integer

   newIndex = frmWebBrowser.WebBrowser.UBound
   Load frmWebBrowser.WebBrowser(newIndex)
   Set thisWebBrowser = frmWebBrowser.WebBrowser(nexIndex)
   ...
End Function

I get "Object or class does not support the set of events" when trying to set thisWebBrowser equal to the one I just created.  Does anyone have any idea how I could make this work?  Thanks.
0
Comment
Question by:vt45
  • 10
  • 5
  • 3
  • +1
19 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6238600
Firstly, I wouldn't dim the form like this(not sure if it would work anyway)
<<Private WithEvents thisWebBrowser As frmWebBrowser>>

<CLASS CODE>

Try:
Dim thisWebBrowser as frmWebBrowser

<INITIALIZE>
'Create a new instance of the form
Set thisWebBrowser = New frmWebBrowser
'Tie the class object to the form
Set thisWebBrowser.objWebClass = Me
thisWebBrowser.show

</CLASS CODE>

<FORM CODE>
Dim objWebClass as clsWidget (or Whatever the name is)

For the events of the browser..

Private sub WebBrowser1_Navigate(...)
  objWebClass.Navigate(...)
End Sub
</FORM CODE>

'This is all from memory, but you should get the point...

Dave


0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6238610
P.S. I think everyone here would agree that this in not an easy problem, and the point award should reflect this...

-d
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6238690
unless i dont understand your naming conventions:

>>Set thisWebBrowser = frmWebBrowser.WebBrowser(nexIndex)

here you are trying to set an instance of your form, frmWebBrowser, equal to a Webbrowser control object.

just out of curiosity, why are you trying to wrap this form up into a class?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6238804
Interesting...
0
 

Author Comment

by:vt45
ID: 6239113
Azra-
Sorry, I goofed up the "Private WithEvents thisWebBrowser As frmWebBrowser" it should read "Private WithEvents thisWebBrowser As WebBrowser". What I want to happen is for the clsWidget class to contain the WebBrowser events.  Eventually I will have clsWidget2, clsWidget3...clsWidget44 and so on.  Each class will have Widget specific code for each event.
0
 

Author Comment

by:vt45
ID: 6239147
Dave-

I see how your code would work.  I may have to do it that way, but I would have to create a frmWebBrowserx for each clsWidegtx.  Hopefully I will find a way to use just one form and create multiple WebBrowser object off that one form.  Thanks.
0
 

Author Comment

by:vt45
ID: 6239199
Dave-

I see how your code would work.  I may have to do it that way, but I would have to create a frmWebBrowserx for each clsWidegtx.  Hopefully I will find a way to use just one form and create multiple WebBrowser object off that one form.  Thanks.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6239213
note that form objects are really just classes themselves, with a UI.  that is why i questioned the design of implementing a wrapper class for this "form class".


>>Eventually I will have clsWidget2, clsWidget3...clsWidget44 and so on.  Each class will have Widget specific code for each event.

so how will this be more beneficial than having frmWebBrowser1, frmWebBrowser2...and so on, with specific code for each event in that form?  i am not trying to be hard on you, just raising some design issues.

it looks like maybe you are trying to use the form as a template, but at the same time, you want multiple webbrowser object without multiple forms.  the webbrowser component can not exist without its form container.  thus, to have multiple instances of the webbrowser, youll need multiple instances of the form (unless you use only a control array for the webbrowser).  it looks like you were already taking that route, but i'm not sure.  perhaps if you could offer some details on what your ultimate goal is here, we can come up with something workable.
0
 

Author Comment

by:vt45
ID: 6239257
Sorry, let me explain further (or at least try to).  One thing to note here is that there will be no user interaction.  This .dll will run on it's own at specified times.  What I really need is HTML document objects to navigate through and capture values of some elements and then store those in the database.  I use alot of the WebBrowser object events, so if I could incorperate those into my class, life would be easier and my code would be more readable for other folks.  Also it would be easier to add new clsWidgets to the project if they all referenced one form. Is this possible!?  If not, does anyone this VB7 will handle something like this?  Thanks again.
0
 

Author Comment

by:vt45
ID: 6239287
Dave-

I see how your code would work.  I may have to do it that way, but I would have to create a frmWebBrowserx for each clsWidegtx.  Hopefully I will find a way to use just one form and create multiple WebBrowser object off that one form.  Thanks.
0
 

Author Comment

by:vt45
ID: 6239291
Azra-
Sorry, I goofed up the "Private WithEvents thisWebBrowser As frmWebBrowser" it should read "Private WithEvents thisWebBrowser As WebBrowser". What I want to happen is for the clsWidget class to contain the WebBrowser events.  Eventually I will have clsWidget2, clsWidget3...clsWidget44 and so on.  Each class will have Widget specific code for each event.
0
 

Author Comment

by:vt45
ID: 6239294
Sorry for the multiple entries!  Guess it's not a good idea to keep refresing this page!  
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 60 total points
ID: 6239303
>>One thing to note here is that there will be no user interaction.

then perhaps you need to look into automating IE instead.  e.g., instead of selecting Microsoft Internet Controls via project -> COMPONENTS, select it via project -> REFERENCES.  then in code, in your class:


Private WithEvents IEObj As SHDocVw.InternetExplorer


'
'-- all code for events for IEObj
'


Private Sub Class_Initialize()
   Set IEObj = New SHDocVw.InternetExplorer
End Sub

Private Sub Class_Terminate()
   IEObj.Quit
   Set IEObj = Nothing
End Sub



>>What I really need is HTML document objects to navigate through and capture values of some elements and then store those in the database

there is a way to only use the HTML Object Library to load documents in and then navigate through the Document Object Model of an HTML Document.  i have never required to do so myself, but that, too, may be an option.
0
 

Author Comment

by:vt45
ID: 6244872
Thanks Azra, i'm in the process of implementing the IE object.  I'm running across a problem though:

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=visualbasic&qid=20144509
0
 

Author Comment

by:vt45
ID: 6249184
Looks like the IE object suits my need.  My problem now is that I have a hard time figuring out which document object i'm on.

Is there anyway I can send a document object to a WebBrowser control just for view purposes?  I've tried:

Set WebBrowser1.Document = IEobj.Document

but that doesn't work.  Any ideas?

Thanks.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6249212
Put the objects into a collection then you can go by the key value...
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6249219
what error do you get with that line of code?
0
 

Author Comment

by:vt45
ID: 6249245
Azra-

Set WebBrowser1.Document = IEobj.Document

Error: "Object doesn't support this property or method"

0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6249317
hmm...strange.  last time i checked, both of those objects supported it...oh well.

an alternative may be:

WebBrowser1.Navigate "about:blank"
Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Loop
Call WebBrowser1.Document.write(IEObj.Document.documentElement.outerhtml)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

790 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