We can create a new object (beyond the built-in objects) by defining a class in the class module. The class module allows you to create new objects, along with corresponding properties, methods, and events. There are certain particular tasks that only a class module can accomplish.
The class module is not an object by itself but a template of the object. It is necessary to make an object based on the class module as the very first essential step. The very first step involves a process called Instantiating to create an object. The instantiation is accomplished following the steps below.
Step | Description | Example |
---|---|---|
1 | Start from the class module named cls_ufe, as an example | The name of class module= cls_ufe |
2 | Declare the class module in the general declaration section of the standard module | Public c_ufe as cls_ufe |
3 | instantiate a class into an object using New keyword | Set c_ufe=New cls_ufe |
There are two cases: one without need to declare new object and another with need to declare new object to be linked with each other.
This case does not require additional declaration to link the standard module with the class module. The object instantiated can be used immediately.
Above Task 3 (Encapsulating multiple Windows application programming interface (API) functions to execute a single procedure) falls into this category.
This case requires to link the object declared in standard procedure with the object to be declared in the class module using the Set keyword to assign a reference to an object.
The object declared in the standard module will carry out actions using the properties and methods to be defined in the class module. If the object is a built-in object, it is possible to use the methods and properties of the object without need to define the methods and properties.
Set c_ufe . (Object_of_class_module) = (Object_of_standard_module)
The class module holds all the methods and properties without additional need to declare objects.
Above Task 3 (Encapsulating multiple Windows application programming interface (API) functions to execute a single procedure) falls into this category.
When the tasks with event procedures of above task 1, 2 and 4 are concerned, it is necessary to declare at the general declaration section of the class module:
Public WithEvents (Object_of_standard_module) As (Built_in_object name)
Dated on:12-NOvember-2019