Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate? 
Author Message
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?

Thanks.

--

Vince C.



Mon, 06 Sep 2004 15:57:19 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
LOL- :)

You *really* want the documentation.

My apologies, by the way - I directed you to the pure US-English docs.  If you prefer, I *think* the following location - which has localized versions of WSH - may have documentation localized for LCIDs other than 1033; I did see both French and Dutch versions of WSH there...

Watch for URL wrap, this will be long -

http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

================================
Here's another one from the docs -
Terminate Event

Applies To: Class Object

Occurs when an instance of the associated class is terminated.
Private Sub Class_Terminate()
   statements
End Sub
The statements part consists of zero or more code statements to be run when the class is initialized.
Remarks
The following example illustrates the use of the Terminate event.
Class TestClass
   Private Sub Class_Initialize   ' Setup Initialize event.
      MsgBox("TestClass started")
   End Sub
    Private Sub Class_Terminate   ' Setup Terminate event.
      MsgBox("TestClass terminated")
   End Sub
End Class
Set X = New TestClass   ' Create an instance of TestClass.
Set X = Nothing   ' Destroy the instance.

: Thanks.
:
: --
:
: Vince C.
:
:
:
:
:
:



Mon, 06 Sep 2004 19:15:18 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
Thank you Alex.

I already have the documentation however but I didn't find anything on
termination events. I know about VBScript's support for Class but what I'd
like to know is about script components (those which are defined in WSC,
XML-Compliant files). The script code that lies in the CDATA section can be
launched when a component is created but I couldn't figure out how (and
simply: if) I could execute code upon destruction.

--

Vince C.

"Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__> wrote

LOL- :)

You *really* want the documentation.

My apologies, by the way - I directed you to the pure US-English docs.  If
you prefer, I *think* the following location - which has localized versions
of WSH - may have documentation localized for LCIDs other than 1033; I did
see both French and Dutch versions of WSH there...

Watch for URL wrap, this will be long -

http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...
sdncompositedoc.xml

================================
Here's another one from the docs -
Terminate Event

Applies To: Class Object

Occurs when an instance of the associated class is terminated.
Private Sub Class_Terminate()
   statements
End Sub
The statements part consists of zero or more code statements to be run when
the class is initialized.
Remarks
The following example illustrates the use of the Terminate event.
Class TestClass
   Private Sub Class_Initialize   ' Setup Initialize event.
      MsgBox("TestClass started")
   End Sub
    Private Sub Class_Terminate   ' Setup Terminate event.
      MsgBox("TestClass terminated")
   End Sub
End Class
Set X = New TestClass   ' Create an instance of TestClass.
Set X = Nothing   ' Destroy the instance.


: Thanks.
:
: --
:
: Vince C.
:
:
:
:
:
:



Mon, 06 Sep 2004 20:07:52 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
I see.

Assuming you have the event exposed in the WSC, you want to set up an event handler within the calling script which will run the code for you.  This can be done either by using a GetRef or, if you are running from within a WSF or VBS file locally, by explicitly using the WScript.CreateObject method with an identifier for the event sink.

What are you going to run this from? Internet Explorer, ASP, or WSH?

: Thank you Alex.
:
: I already have the documentation however but I didn't find anything on
: termination events. I know about VBScript's support for Class but what I'd
: like to know is about script components (those which are defined in WSC,
: XML-Compliant files). The script code that lies in the CDATA section can be
: launched when a component is created but I couldn't figure out how (and
: simply: if) I could execute code upon destruction.
:
: --
:
: Vince C.
:
:
: "Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__> wrote

: LOL- :)
:
: You *really* want the documentation.
:
: My apologies, by the way - I directed you to the pure US-English docs.  If
: you prefer, I *think* the following location - which has localized versions
: of WSH - may have documentation localized for LCIDs other than 1033; I did
: see both French and Dutch versions of WSH there...
:
: Watch for URL wrap, this will be long -
:
: http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...
: sdncompositedoc.xml
:
:
:
: ================================
: Here's another one from the docs -
: Terminate Event
:
: Applies To: Class Object
:
: Occurs when an instance of the associated class is terminated.
: Private Sub Class_Terminate()
:    statements
: End Sub
: The statements part consists of zero or more code statements to be run when
: the class is initialized.
: Remarks
: The following example illustrates the use of the Terminate event.
: Class TestClass
:    Private Sub Class_Initialize   ' Setup Initialize event.
:       MsgBox("TestClass started")
:    End Sub
:     Private Sub Class_Terminate   ' Setup Terminate event.
:       MsgBox("TestClass terminated")
:    End Sub
: End Class
: Set X = New TestClass   ' Create an instance of TestClass.
: Set X = Nothing   ' Destroy the instance.
:
:


: : Thanks.
: :
: : --
: :
: : Vince C.
: :
: :
: :
: :
: :
: :
:
:
:



Mon, 06 Sep 2004 20:20:22 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
WSCs don't support the equivalent of the VB/VBA/VBScript class Class_Initialize/Terminate handlers.  A *hack* is to create a private vbscript class instance within the WSC when the WSC is first created.  

The vbscript class implements only the Class_Terminate handler.  All it does is serve as a proxy to call a private clean up method within the WSC.  When the WSC goes out of scope and is being torn down, so is the internal vbscript class instance, which fires the instance's Class_Terminate handler which calls the WSC's clean up method...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--

Quote:

> Thank you Alex.

> I already have the documentation however but I didn't find anything on
> termination events. I know about VBScript's support for Class but what I'd
> like to know is about script components (those which are defined in WSC,
> XML-Compliant files). The script code that lies in the CDATA section can be
> launched when a component is created but I couldn't figure out how (and
> simply: if) I could execute code upon destruction.

> --

> Vince C.

> "Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__> wrote

> LOL- :)

> You *really* want the documentation.

> My apologies, by the way - I directed you to the pure US-English docs.  If
> you prefer, I *think* the following location - which has localized versions
> of WSH - may have documentation localized for LCIDs other than 1033; I did
> see both French and Dutch versions of WSH there...

> Watch for URL wrap, this will be long -

> http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...
> sdncompositedoc.xml

> ================================
> Here's another one from the docs -
> Terminate Event

> Applies To: Class Object

> Occurs when an instance of the associated class is terminated.
> Private Sub Class_Terminate()
>    statements
> End Sub
> The statements part consists of zero or more code statements to be run when
> the class is initialized.
> Remarks
> The following example illustrates the use of the Terminate event.
> Class TestClass
>    Private Sub Class_Initialize   ' Setup Initialize event.
>       MsgBox("TestClass started")
>    End Sub
>     Private Sub Class_Terminate   ' Setup Terminate event.
>       MsgBox("TestClass terminated")
>    End Sub
> End Class
> Set X = New TestClass   ' Create an instance of TestClass.
> Set X = Nothing   ' Destroy the instance.



> : Thanks.
> :
> : --
> :
> : Vince C.
> :
> :
> :
> :
> :
> :



Tue, 07 Sep 2004 01:02:41 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
Thanks, Michael and Alex. I was asking that question because I wanted to
know how to use ADO in script components. If there were some kind of a
"Terminate" event, I could have created a connection at startup, for
instance, and close/free it upon destruction (ADO objects require to be
closed and freed explicitly in ASP to avoid troubles).

Now two options: either using Michael's hack (and allocate/free ADO's object
in the internal Class, maybe) or create/open/close/free the ADO object in
each script component's method in which ADO is involved. I think the latter
will lead to performance issues because of the overhead.

Anyway it's good to know.

Thanks again.

--

Vince C.


WSCs don't support the equivalent of the VB/VBA/VBScript class
Class_Initialize/Terminate handlers.  A *hack* is to create a private
vbscript class instance within the WSC when the WSC is first created.

The vbscript class implements only the Class_Terminate handler.  All it does
is serve as a proxy to call a private clean up method within the WSC.  When
the WSC goes out of scope and is being torn down, so is the internal
vbscript class instance, which fires the instance's Class_Terminate handler
which calls the WSC's clean up method...

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--


Quote:
> Thank you Alex.

> I already have the documentation however but I didn't find anything on
> termination events. I know about VBScript's support for Class but what I'd
> like to know is about script components (those which are defined in WSC,
> XML-Compliant files). The script code that lies in the CDATA section can
be
> launched when a component is created but I couldn't figure out how (and
> simply: if) I could execute code upon destruction.

> --

> Vince C.

> "Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__>
wrote

> LOL- :)

> You *really* want the documentation.

> My apologies, by the way - I directed you to the pure US-English docs.  If
> you prefer, I *think* the following location - which has localized
versions
> of WSH - may have documentation localized for LCIDs other than 1033; I did
> see both French and Dutch versions of WSH there...

> Watch for URL wrap, this will be long -

http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

- Show quoted text -

Quote:
> sdncompositedoc.xml

> ================================
> Here's another one from the docs -
> Terminate Event

> Applies To: Class Object

> Occurs when an instance of the associated class is terminated.
> Private Sub Class_Terminate()
>    statements
> End Sub
> The statements part consists of zero or more code statements to be run
when
> the class is initialized.
> Remarks
> The following example illustrates the use of the Terminate event.
> Class TestClass
>    Private Sub Class_Initialize   ' Setup Initialize event.
>       MsgBox("TestClass started")
>    End Sub
>     Private Sub Class_Terminate   ' Setup Terminate event.
>       MsgBox("TestClass terminated")
>    End Sub
> End Class
> Set X = New TestClass   ' Create an instance of TestClass.
> Set X = Nothing   ' Destroy the instance.



> : Thanks.
> :
> : --
> :
> : Vince C.
> :
> :
> :
> :
> :
> :



Tue, 07 Sep 2004 19:53:48 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
Doesn't connection pooling completely negate the overhead by allowing you to
reuse an existing connection without the connection having to be
re-established?

[Unless its a DSN because I believe that ODBC doesn't support pooling?]

Chris Barber.


Quote:
> Thanks, Michael and Alex. I was asking that question because I wanted to
> know how to use ADO in script components. If there were some kind of a
> "Terminate" event, I could have created a connection at startup, for
> instance, and close/free it upon destruction (ADO objects require to be
> closed and freed explicitly in ASP to avoid troubles).

> Now two options: either using Michael's hack (and allocate/free ADO's
object
> in the internal Class, maybe) or create/open/close/free the ADO object in
> each script component's method in which ADO is involved. I think the
latter
> will lead to performance issues because of the overhead.

> Anyway it's good to know.

> Thanks again.

> --

> Vince C.



> WSCs don't support the equivalent of the VB/VBA/VBScript class
> Class_Initialize/Terminate handlers.  A *hack* is to create a private
> vbscript class instance within the WSC when the WSC is first created.

> The vbscript class implements only the Class_Terminate handler.  All it
does
> is serve as a proxy to call a private clean up method within the WSC.
When
> the WSC goes out of scope and is being torn down, so is the internal
> vbscript class instance, which fires the instance's Class_Terminate
handler
> which calls the WSC's clean up method...

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US
> --



> > Thank you Alex.

> > I already have the documentation however but I didn't find anything on
> > termination events. I know about VBScript's support for Class but what
I'd
> > like to know is about script components (those which are defined in WSC,
> > XML-Compliant files). The script code that lies in the CDATA section can
> be
> > launched when a component is created but I couldn't figure out how (and
> > simply: if) I could execute code upon destruction.

> > --

> > Vince C.

> > "Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__>
> wrote

> > LOL- :)

> > You *really* want the documentation.

> > My apologies, by the way - I directed you to the pure US-English docs.
If
> > you prefer, I *think* the following location - which has localized
> versions
> > of WSH - may have documentation localized for LCIDs other than 1033; I
did
> > see both French and Dutch versions of WSH there...

> > Watch for URL wrap, this will be long -

http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

- Show quoted text -

Quote:
> > sdncompositedoc.xml

> > ================================
> > Here's another one from the docs -
> > Terminate Event

> > Applies To: Class Object

> > Occurs when an instance of the associated class is terminated.
> > Private Sub Class_Terminate()
> >    statements
> > End Sub
> > The statements part consists of zero or more code statements to be run
> when
> > the class is initialized.
> > Remarks
> > The following example illustrates the use of the Terminate event.
> > Class TestClass
> >    Private Sub Class_Initialize   ' Setup Initialize event.
> >       MsgBox("TestClass started")
> >    End Sub
> >     Private Sub Class_Terminate   ' Setup Terminate event.
> >       MsgBox("TestClass terminated")
> >    End Sub
> > End Class
> > Set X = New TestClass   ' Create an instance of TestClass.
> > Set X = Nothing   ' Destroy the instance.



> > : Thanks.
> > :
> > : --
> > :
> > : Vince C.
> > :
> > :
> > :
> > :
> > :
> > :



Thu, 09 Sep 2004 06:09:10 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
Chris, I read at http://www.15seconds.com/issue/970531.htm that ODBC
supports connection pooling since version 3.0. However I didn't think of it.
But The reason I was about to wrap ADO objects was to find a work around to
not closing and assigning ADO components to nothing at the end of a script.
ADO recordsets and connections must be explicitly closed otherwise
"problems" may occur.

But now I think I understand a bit more those problems. However I'd like to
know if the effect of not assigning recordset variables to nothing is the
same as with connections. Does it really hurt when I don't "Set rs =
Nothing" after "rs.Close" and what is its impact?

Thanks.

--

Vince C.


Quote:
> Doesn't connection pooling completely negate the overhead by allowing you
to
> reuse an existing connection without the connection having to be
> re-established?

> [Unless its a DSN because I believe that ODBC doesn't support pooling?]

> Chris Barber.



> > Thanks, Michael and Alex. I was asking that question because I wanted to
> > know how to use ADO in script components. If there were some kind of a
> > "Terminate" event, I could have created a connection at startup, for
> > instance, and close/free it upon destruction (ADO objects require to be
> > closed and freed explicitly in ASP to avoid troubles).

> > Now two options: either using Michael's hack (and allocate/free ADO's
> object
> > in the internal Class, maybe) or create/open/close/free the ADO object
in
> > each script component's method in which ADO is involved. I think the
> latter
> > will lead to performance issues because of the overhead.

> > Anyway it's good to know.

> > Thanks again.

> > --

> > Vince C.



> > WSCs don't support the equivalent of the VB/VBA/VBScript class
> > Class_Initialize/Terminate handlers.  A *hack* is to create a private
> > vbscript class instance within the WSC when the WSC is first created.

> > The vbscript class implements only the Class_Terminate handler.  All it
> does
> > is serve as a proxy to call a private clean up method within the WSC.
> When
> > the WSC goes out of scope and is being torn down, so is the internal
> > vbscript class instance, which fires the instance's Class_Terminate
> handler
> > which calls the WSC's clean up method...

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > Seattle WA US
> > --



> > > Thank you Alex.

> > > I already have the documentation however but I didn't find anything on
> > > termination events. I know about VBScript's support for Class but what
> I'd
> > > like to know is about script components (those which are defined in
WSC,
> > > XML-Compliant files). The script code that lies in the CDATA section
can
> > be
> > > launched when a component is created but I couldn't figure out how
(and
> > > simply: if) I could execute code upon destruction.

> > > --

> > > Vince C.

> > > "Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__>
> > wrote

> > > LOL- :)

> > > You *really* want the documentation.

> > > My apologies, by the way - I directed you to the pure US-English docs.
> If
> > > you prefer, I *think* the following location - which has localized
> > versions
> > > of WSH - may have documentation localized for LCIDs other than 1033; I
> did
> > > see both French and Dutch versions of WSH there...

> > > Watch for URL wrap, this will be long -

http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

- Show quoted text -

Quote:
> > > sdncompositedoc.xml

> > > ================================
> > > Here's another one from the docs -
> > > Terminate Event

> > > Applies To: Class Object

> > > Occurs when an instance of the associated class is terminated.
> > > Private Sub Class_Terminate()
> > >    statements
> > > End Sub
> > > The statements part consists of zero or more code statements to be run
> > when
> > > the class is initialized.
> > > Remarks
> > > The following example illustrates the use of the Terminate event.
> > > Class TestClass
> > >    Private Sub Class_Initialize   ' Setup Initialize event.
> > >       MsgBox("TestClass started")
> > >    End Sub
> > >     Private Sub Class_Terminate   ' Setup Terminate event.
> > >       MsgBox("TestClass terminated")
> > >    End Sub
> > > End Class
> > > Set X = New TestClass   ' Create an instance of TestClass.
> > > Set X = Nothing   ' Destroy the instance.



> > > : Thanks.
> > > :
> > > : --
> > > :
> > > : Vince C.
> > > :
> > > :
> > > :
> > > :
> > > :
> > > :



Sun, 12 Sep 2004 23:41:07 GMT  
 Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?
Sorry Vince, completly missed your response to my last post.

It doesn't really matter - once the object reference goes out of scope (eg.
a private variable at the exit point of a function) it wil be destroyed
anyway as a matter of course. However, it's not really good practice to
*depend* on this. There are circumstances when this could fail (generally
badly designed dll's for example).

In your case, I wouldn't worry.

Still, you should try to encapsulate all you ADO stuff into functions and
methods that explicitly create and destroy the object as they enter and
exit. That's the holy grail.

Chris Barber.


Chris, I read at http://www.15seconds.com/issue/970531.htm that ODBC
supports connection pooling since version 3.0. However I didn't think of it.
But The reason I was about to wrap ADO objects was to find a work around to
not closing and assigning ADO components to nothing at the end of a script.
ADO recordsets and connections must be explicitly closed otherwise
"problems" may occur.

But now I think I understand a bit more those problems. However I'd like to
know if the effect of not assigning recordset variables to nothing is the
same as with connections. Does it really hurt when I don't "Set rs =
Nothing" after "rs.Close" and what is its impact?

Thanks.

--

Vince C.


Quote:
> Doesn't connection pooling completely negate the overhead by allowing you
to
> reuse an existing connection without the connection having to be
> re-established?

> [Unless its a DSN because I believe that ODBC doesn't support pooling?]

> Chris Barber.



> > Thanks, Michael and Alex. I was asking that question because I wanted to
> > know how to use ADO in script components. If there were some kind of a
> > "Terminate" event, I could have created a connection at startup, for
> > instance, and close/free it upon destruction (ADO objects require to be
> > closed and freed explicitly in ASP to avoid troubles).

> > Now two options: either using Michael's hack (and allocate/free ADO's
> object
> > in the internal Class, maybe) or create/open/close/free the ADO object
in
> > each script component's method in which ADO is involved. I think the
> latter
> > will lead to performance issues because of the overhead.

> > Anyway it's good to know.

> > Thanks again.

> > --

> > Vince C.



> > WSCs don't support the equivalent of the VB/VBA/VBScript class
> > Class_Initialize/Terminate handlers.  A *hack* is to create a private
> > vbscript class instance within the WSC when the WSC is first created.

> > The vbscript class implements only the Class_Terminate handler.  All it
> does
> > is serve as a proxy to call a private clean up method within the WSC.
> When
> > the WSC goes out of scope and is being torn down, so is the internal
> > vbscript class instance, which fires the instance's Class_Terminate
> handler
> > which calls the WSC's clean up method...

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > Seattle WA US
> > --



> > > Thank you Alex.

> > > I already have the documentation however but I didn't find anything on
> > > termination events. I know about VBScript's support for Class but what
> I'd
> > > like to know is about script components (those which are defined in
WSC,
> > > XML-Compliant files). The script code that lies in the CDATA section
can
> > be
> > > launched when a component is created but I couldn't figure out how
(and
> > > simply: if) I could execute code upon destruction.

> > > --

> > > Vince C.

> > > "Alex K. Angelopoulos" <alex_angelopoulos_at_hotmail_dot_com_remove__>
> > wrote

> > > LOL- :)

> > > You *really* want the documentation.

> > > My apologies, by the way - I directed you to the pure US-English docs.
> If
> > > you prefer, I *think* the following location - which has localized
> > versions
> > > of WSH - may have documentation localized for LCIDs other than 1033; I
> did
> > > see both French and Dutch versions of WSH there...

> > > Watch for URL wrap, this will be long -

http://msdn.microsoft.com/downloads/sample.asp?url=/MSDN-FILES/027/00...

- Show quoted text -

Quote:
> > > sdncompositedoc.xml

> > > ================================
> > > Here's another one from the docs -
> > > Terminate Event

> > > Applies To: Class Object

> > > Occurs when an instance of the associated class is terminated.
> > > Private Sub Class_Terminate()
> > >    statements
> > > End Sub
> > > The statements part consists of zero or more code statements to be run
> > when
> > > the class is initialized.
> > > Remarks
> > > The following example illustrates the use of the Terminate event.
> > > Class TestClass
> > >    Private Sub Class_Initialize   ' Setup Initialize event.
> > >       MsgBox("TestClass started")
> > >    End Sub
> > >     Private Sub Class_Terminate   ' Setup Terminate event.
> > >       MsgBox("TestClass terminated")
> > >    End Sub
> > > End Class
> > > Set X = New TestClass   ' Create an instance of TestClass.
> > > Set X = Nothing   ' Destroy the instance.



> > > : Thanks.
> > > :
> > > : --
> > > :
> > > : Vince C.
> > > :
> > > :
> > > :
> > > :
> > > :
> > > :



Wed, 10 Nov 2004 03:16:17 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Is there an event fired inside a script component when it is destroyed, like VB's Class_Terminate?

2. i am new to VB script ..appreciate any help

3. ATL COM Component firing events into VBScript event sink

4. I am looking for a HTTP/1.1 ASP component

5. I am looking for a HTTP/1.1 ASP component

6. I am learning VB.NET and am wondering....

7. Firing events from a form inside a class inside a test app

8. ADSI and VB HELP I am NEW

9. I am trying to update a record, i am not using data control

10. I am trying to update a record, i am not using data control

11. Destroying ActiveX EXE Object Does Not Fire The Class_Terminate Event

12. Calculations and validations inside Datagrid(i am using sqlServer database)

 

 
Powered by phpBB® Forum Software