<billymyersiii@xxxxxx> wrote in message
news:45f970d8-7a5b-46fe-a529-ea866c004cc2@xxxxxx
> I am having trouble determining how to get this to work if possible. I
> need to have different class instances write html to a single class
> instance that creates one InternetExplorer.Application Window and has
> a method that captures all data from the other classes.
>
> Expected result is: 1 window will popup and display the text from all
> method calls th addhtml
>
> Dim cls1, cls2
>
> Set cls1 = New TestClass
> Set cls2 = New TestClass
>
> cls1.addhtml("<b>test1</b>")
> cls2.addhtml("<b>test2</b>")
>
> Class TestClass
>
> End Class
>
> Class TestClass
> addhtml("<b>test3</b>")
> End Class
>
> Class TestClass
> addhtml("<b>test4</b>")
> End Class
>
> Class TestIE
> Private oIE
> Public Function addhtml(html)
> If NOT (oIE is Nothing) Then
> Set oIE = CreateObject
> ("InternetExplorer.Application")
> oIE.visible=1
> End If
> oIE.document.write html
> End Function
> End Class
Option Explicit
Class IeWriter
Dim MyIE
Public Function addhtml(html)
MyIE.document.write html
End Function
End Class
Dim cls1, cls2, globalIE
' You want a single IE instance to be used by multiple class
' instances. To make it work, you need to create the IE instance
' in one location and ensure that apps using it have a ref
' to the same instance.
' One way that works is this.
' First, create a global IE object
Set globalIE = CreateObject("InternetExplorer.Application")
' navigate, wait, then make it visible.
globalIE.Navigate "about
:blank"
do while globalIE.ReadyState <> 4: WScript.Sleep 20: Loop
globalIE.Visible = true
' Now create an instance of our IeWriter class:
Set cls1 = New IeWriter
' The IeWriter has a public MyIE property that we can fill with
' our global IE instance:
Set cls1.MyIE = globalIE
'Now repeat for another instance of the IeWriter class:
Set cls2 = New IeWriter
Set cls2.MyIE = globalIE
cls1.addhtml "<b>test1</b>"
cls2.addhtml "<b>test2</b>"