The previous sections of this chapter have discussed how you can implement a custom object's
properties, methods, events, and collections in a class module.
Now it is time to see how to use a custom object in controlling code. Such code might reside in
another module in the same application or in a separate ActiveX client.
Declaring and Instantiating a Class Object
You have two basic options for actually instantiating a Class object: Declare it like any other variable
and assign its contents later, or instantiate the object when you declare it.
Declare Now, Instantiate Later
You can declare the custom object somewhere in your code just as you would declare a VB variable
of a standard variable type. Use the class name as the variable, as in the following example:
Private FF As FileFind
Later in your code, you need to use the Set and New keywords to instantiate the object:
Set FF = New FileFind
Instantiate
When You Declare
You can declare a Class object and instantiate it with a single statement by using the New keyword
in the declaration statement:
Private FF As New FileFind
Declaring WithEvents
If you plan to program the Class object's event procedures, you must use the WithEvents
keyword in the declaration, as in the following example:
Private WithEvents FF As FileFind
You can't use the New keyword in a WithEvents declaration, so you always have
to instantiate these Class objects later, as described above in the section titled,
"Instantiate When You Declare".