When programmer wants to create an object variable from a class, first adds a reference to that class using the VB Project References menu item.
1) Declaring the variable using the New keyword (in statement like Dim, Public, or Private), which means VB automatically assigns a new object reference the first time programmer uses the variable (for example, when programmer refers to one of its methods or properties).
Dim Object Name As New Object Type
As an example, here an object named objSorter is created of the Sorter class:
Dim objSorter As New Sorter
2) Declare an object variable then assigning a reference to a new object in a Set statement by using the New keyword.
Dim Object Name As ObjectType
Set Object Name = New ObjectType
SETTING OBJECT PROPERTIES
After creating the object now programmer can access the public properties and procedures of a class using the following syntax.
3) Assigning a reference to a new object in a Set statement by using CreateObject function. To use “Create Object” the name of the class is passed.
Dim Object Name As Object
Set ObjectName = CreateObject(“className”)
CLASS INSTANCE AND INHERITANCE
When an object of a class is created then there may be two types of cases.
1. A new instance of a class is created.
2. No new instance is created.
Other applications aren’t allowed to access a class and cannot create instances of it. Private objects are only for use within your component.
Public Not Creatable.
Global Multi Use.
Global Single Use.