• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Class implementation help please

B

billymyersiii

#1
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
 

My Computer

A

Alex K. Angelopoulos

#2
<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>"
 

My Computer

B

billymyersiii

#3
I'm sorry, I currently have it working this way, but looking for a way
to let the class(s) handle the implementation not the calling code. It
makes no sense to implement this code every time if it is a
requirement across all classes. That is why I am trying to move it out
of the calling code and into the class code. It seems that everytime I
try to do so I end up with multiple IE windows if you know what I
mean.




On Jun 5, 4:07 pm, "Alex K. Angelopoulos" <alex(dot) k(dot again)
angelopoulos(at)gmail.com> wrote:

> <billymyers...@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>"- Hide quoted text -
>
> - Show quoted text -
 

My Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)