Understanding Class in VBScripting

What is a Class?

A Class is a template or a blueprint for an object. An object exists only in memory at runtime; a class is a programming construct that we can work only directly during design time. Now for using object at runtime we need to define a class at design time. Objects are thus only created at runtime based on the template provided by class.

One’s class is defined; we can create numerous objects in memory.

Scope of Class members?
Within a Class block, members are declared as either Private or Public using the appropriate declaration statements. Anything declared as Private is visible only within the Class block. Anything declared as Public is visible within the Class block, as well as by code outside the Class block.

How to create class?
To create a class we use the Keyword “Class”, like we use Function or Sub to define functions or Subroutine.

Class UFTHelp
                ‘Code for class
End Class
Class: – Keyword used to define the class
UFTHelp: – User defined name of the class

What is a property?
When an object is created from class, then we use properties to access and store data from the object.

Types of property?

1. Property Let:-It allows code outside of a class to place a value in a property variable. Thus it is same like a “Sub” Procedure in that it does not return a value.

2.Property Get:-Is the inverse of a “Property Let” , thus it allows code outside of class to read value of property variable,thus it is same like a “Function” procedure in that it returns a value.

3. Property Set: – Is same to “Property Let”, but it is exclusively used to set values for an object-based properties. Point is that it is used to set values for an object (FilesystemObject), rather than a variable with a numeric, date.

Defining a Method?
It is same as defining a Function or Sub procedure

We cannot nest classes.
Test script can have multiple classes
Keywords cannot be used to define the name of the class
By default all members of class are Public
Property Let must accept at least one value.

One reply on “Understanding Class in VBScripting”

Why would use a Class in UFT/VBScript? What advantage and/or additional functionality does it give you. If you know how to use RegisterUserFunc in QTP/UFT to create your own custom methods for objects (like WinCombobox, WinList, WinListView, WinObject, Acx_table, Swf_Edit, etc.) then you're in good shape.

Classes in VBScript and QTP/UFT are overkill.

Leave a Reply

Your email address will not be published. Required fields are marked *