CREATING OBJECTS VARIABLE

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).

SYNTAX

Dim Object Name As New Object Type

EXAMPLE

As an example, here an object named objSorter is created of the Sorter class:

Dim objSorter As New Sorter

objSorter.Sort

2)   Declare an object variable then assigning a reference to a new object in a Set statement by using the New keyword.

SYNTAX

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.

ObjectName.PropertyName

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.

SYNTAX

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.

PRIVATE

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.

Multi Use.

Global Multi Use.

Single Use.

Global Single Use.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s