Variable – Environment,scalar,Array

Definition: Variable is a place-holder where you can store some value in the computer’s memory. It will have a name which can be used to access or modify its value.

In Vbscript, variable are of datatype ‘Variant’.

Types of variable:
1. Scalar Variable
2. Array
3. Environment variable(UFT specific)

First, we will discuss about the Scalar.It has a naming convention as given below.

  •    MUST always begin with an alpha character.
  •    MUST NOT exceed 255 characters
  •    MUST NOT have a period character
  •    MUST NOT be the name of a predefined keyword used in VBScript.
  •    MUST be a unique name in the scope in which it is declared

Correct: val123,val, val_12
Incorrect: 123val, val.123,val. , val.val, Date etc.

Is it possible to override the predefined variable or incorrect variables?
Yes, by placing the variable name into a brackets.

Note: Note:
Dim : It is used to allocate storage space for one or more variables i.e. declaring variables.

Declaring variables:
If variable defined at script level then variable will be available in all procedures of the script and if defined in  procedure, then it will be available in that procedure only.
It is not mandatory to use Dim statement while declaring variables. If omit,  the variable will be allocated memory in the computer and value can be assigned to it.
e.g. Dim name  or name

Option Explicit: It forces the user to declare the variable by using keyword Dim. If Dim is not used, it will throw an error message “Variable is undefined.”



What is Array?
Array is a kind of container which can contain multiple values. Values can be of any datatype like integer,string etc. The values in array is stored on the integer index basic like 0,1,2,3.. etc.
The first value will be 0 index and second at 1 and so on..

We need to define the sizeof the array at the time of declaration. Please look at the example below.


In this example, size of the array is 3. Values can be stored at indexes 0,1,2 only.

Environment Variables: These variable are an in-built feature of UFT. These are nothing but the Global variables. If once defined in any script, these can be accessed across all the script during execution.

Types of Environment Variables:
There are 2 types of environment variables.

1. Built-In environment variables
2. User defined environment variables

It can be seen or defined at the location ‘File –> Settings –>Environment(Tab)’.


Built-In environment variable are predefined variables which provide the information about Actions like Action name,Action iteration and OS version,Local host name,Testname etc.

User Defined environment variables are created by users. They can be of 2 types as given below.
1. Internal Environment variables
2. External Environment variables

Internal Environment variables : These variables can be given a name and value and then can be accessed in the program with the below syntax.
syntax: getvalue Environment.Value(“ActionName”)
In the below screen , we can see a + sign. Click on that and add name & value. You can observe the type as ‘Internal’ highlighted.

Environment loading

Export Button: This button is used to save the Internal environment variables at any desired path , if required. It will be an XML file.

Load variable and values from external file: It is also possible to upload an xml file containing the Environment variables. It will be having the same format of file which you get after exporting.

Can we define environment variable at run time?
Yes, it possible.
Environment.value(“Myvar”) = “12345”

We can upload the environment variable file at run time as well(as given below).

Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...

Leave a Reply

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