A Variable is a Container to Store the Values.
VBScript variables are used to hold values or expressions. When you are going to use a variable in your VBScript code you should first declare it. Creating variables in VBScript is most often referred to as “declaring” variables.
- A variable can store more than one value by emptying previous value.
- It’s not mandatory to declare a variable.
- It’s not mandatory to use Dim to declare a variable.
- A variable can store any type of data.
firstname = “noor”
address=”202 Dahill Road”
You declare variables explicitly in your script using the Dim (Dimension) statement, the Public statement, and the Private statement. For example: Dim i
You declare multiple variables by separating each variable name with a comma. For example:
Dim i, j, k, l
You can also declare a variable implicitly by simply using its name in your script. That is not generally a good practice because you could misspell the variable name in one or more places, causing unexpected results when your script is run.
For that reason, the Option Explicit statement is available to require explicit declaration of all variables. The Option Explicit statement should be the first statement in your script.
Variables Naming Restrictions
Variable names follow the standard rules for naming anything in VBScript. A variable name:
- Must begin with an alphabetic character.
- Cannot contain an embedded period.
- Must not exceed 255 characters. (Less than 32 characters is best)
- Must be unique in the scope in which it is declared.
- Variable name cannot be a Keyword. (Keywords are the reserved word in any programming language)
- Should not have spaces , _ in the variable name
Types of Variable
There are two types of Variable in VBScript – Local Variable and Global Variable.
- Local Variable
- Global Variable
Local Variable: Variables created inside your Function/Sub-procedure are called Local Variables. We can not access this variables from outside the Function.
Global Variable: A Global Variable is a variable that can be accessed anywhere inside the test case/script.
To learn more check out VBScript Variables.
Continuation Operator: If you want to initialize multiple values in the same line, use:
Dim i, j, k