UFT/QTP – VBScript Tutorial Part -1

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.

Data Types

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.

VarType Function

Returns a value indicating the subtype of a variable.

Syntax  VarType(varname)
The varname argument can be any variable.

The VarType function returns the following values:

Constant Value Description
vbEmpty 0 Empty (uninitialized)
vbNull 1 Null (no valid data)
vbInteger 2 Integer
vbLong 3 Long integer
vbSingle 4 Single-precision floating-point number
vbDouble 5 Double-precision floating-point number
vbCurrency 6 Currency
vbDate 7 Date
vbString 8 String
vbObject 9 Automation object
vbError 10 Error
vbBoolean 11 Boolean
vbVariant 12 Variant (used only with arrays of Variants)
vbDataObject 13 A data-access object
vbByte 17 Byte
vbArray 8192 Array


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.

Example –

  1. ‘Program to print Variable Type.
  2. x= 3.14
  3. y=”String Variable”
  4. print(VarType(x))
  5. print(VarType(y))

Description –

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”

Naming Restrictions

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


Leave a Reply

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