Understanding Class in VBScripting – User friendly Tech help
n
What is a Class?
n
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.
n
Example:-
n
One’s class is defined; we can create numerous objects in memory.
n
Scope of Class members?
nWithin 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.
n
How to create class?
n
To create a class we use the Keyword “Class”, like we use Function or Sub to define functions or Subroutine.
n
Syntax:-
n
Class UFTHelp
n
‘Code for class
n
End Class
n
Class: – Keyword used to define the class
n
UFTHelp: – User defined name of the class
n
What is a property?
n
When an object is created from class, then we use properties to access and store data from the object.
n
Types of property?
n
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.
n
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.
n
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.
n
Defining a Method?
n
It is same as defining a Function or Sub procedure
n
Important:-
n
We cannot nest classes.
n
Test script can have multiple classes
n
Keywords cannot be used to define the name of the class
n
By default all members of class are Public
n
Property Let must accept at least one value.