Software Testing


Variables tutorials
-
A variable is a placeholder or recognizable name for memory location. We stores program information in those variable that may change at run time. A variable is referred to by its name for accessing the value stored or to modify its value. As value varies from time to time during program execution it is called Variable.
Variable Naming Convention
There are standard rules for naming variables in VBScript. A variable name:
-
Variable name must begin with an alphabetic character. It can contain Characters, Number and Underscore.
-
Other signs, spaces and Symbols are not allowed
-
Variable name must not exceed 255 characters. Try to make it upto 20 characters to make it readable.
-
Variable name must be unique in the scope in which it is declared.
-
Variable name must not use reserved Words and VBScript keywords.
-
In VBScript Variable names are NOT case-sensitive. So mname is same as mName.
-
Many programmers start variable name with "m" that stands for memory variable.
Variable Declaration
-
Unlike many programming languages, VBScript allows the implicit declaration of variable. This means that as soon as you use a variable in your script, VBScript does all the necessary work of allocating memory and the variable is considered as declared. However as good programming practice one can explicitly declare any variable at the beginning of script by using Dim statement.
Syntax
Dim Variable_name
For example:
Dim mName
Dim mAge
-
Multiple variables can be declared by separating each variable name with a comma.
For example:
Dim Top, Left, Bottom, Right
Assigning Values to Variables
-
Values are assigned to variables creating an expression as follows: the variable is on the left side of the expression and the value you want to assign to the variable is on the right.
For example:
A = 100
B = 200
C = A + B
Scalar Variable and Array Variable
-
Most of the times you want to assign a single value to a variable you have declared. A variable containing a single value is a scalar variable. However sometimes, you may want to assign more than one related values to a single variable. Then you can create a variable that can contain a series of values. This is called an array variable. Array variables and scalar variables are declared in the same way, except that the declaration of an array variable uses parentheses ( ) following the variable name. In the following example, a single-dimension array containing 11 elements is declared:
Dim No(10)
-
Although the number shown in the parentheses is 10, all arrays in VBScript are zero-based, so this array actually contains 11 elements. So Dim statement creates an Array whose location range from No(1) to No(10).