Solved

Using WebBrowser Control within Class Modules

Posted on 2001-06-29
19
259 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

757 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

23 Experts available now in Live!

Get 1:1 Help Now