VBScript stands for Visual Basic Scripting. This Scripting language developed by Microsoft, supported by Internet Explorer. VBScript is the primary scripting language for Quick Test Professional (QTP), which is a test automation tool.
VBScript has only one data type called a Variant. A Variant is a special kind of data type that can contain different kinds of information, depending on how it’s used.
Variant data types divided into sub data types according to behavior of data type. Like – Empty, Null, Boolean, Byte, Integer, Currency, Long, Single, Double, Date, String Object Error.
Returns a value indicating the subtype of a variable.
The VarType function returns the following values:
|vbNull||1||Null (no valid data)|
|vbSingle||4||Single-precision floating-point number|
|vbDouble||5||Double-precision floating-point number|
|vbVariant||12||Variant (used only with arrays of Variants)|
|vbDataObject||13||A data-access object|
Comments are the non executable line of a script. Comments are used in scripts for better readability and maintenance. In VBScript comments can be provided in two ways. Use ‘ (Single code) or REM.
- ‘Program to print Variable Type.
- x= 3.14
- y=”String Variable”
Line 1 – Define comments
Line 2 – x is assigned with Floating Number
Line 3 – Y is assigned with String
Line 4, 5 print sub data type 5 for double and 8 fro string as per above table.
A variable is a convenient placeholder that refers to a computer memory location.
There are two ways you can declare your variables:
Explicit Declaration: Declare variables explicitly in your script using :
- Dim Statement: Variables declared with Dim at the script level are available to all procedures within script. If the variable declare in procedure then available only within the procedure.
- Public Statement: Variables declared using the public statement are available to all procedures in all scripts of all projects.
- Private Statement: Private variables are available only to the script in which they are declared.
Implicit Declaration: You can also declare a variable implicitly by simply using its name in your script. In this method directly the name of the variable is used value is assigned to a variable whenever required.
The values that do not alter during the entire execution of the program are called as constants. These fixed values defined in the script using the Const statement.
Example – Const myname =”Automationtutorial.com”
Variable names follow the standard rules for naming anything in VBScript. A variable name:-
- Must begin with an alphabetic character
- Can not contain a period
- Must be unique in the scope in which it is declared
- Must not exceed 255 characters