Class module events

Every class module has two events: Initialize and Terminate. The Initialize event is triggered when a new instance of the object is created; the Terminate event is triggered when the object is destroyed. You might want to use the Initialize event to set default property values.

The frameworks for these event handler procedures are as follows:

Private Sub Class_Initialize()

Initialization code goes here End Sub

Private Sub Class_Terminate()

Termination code goes here End Sub

An object is destroyed (and its memory is freed) when the procedure or module in which it is declared finishes executing. You can destroy an object at any time by setting it to Nothing. The following statement, for example, destroys the object named MyObject:

Set MyObject = Nothing

0 0

Post a comment