This section provides a quick introduction of what is a variable and how variable can be declared explicitly with a Dim statement and implicitly with an assignment statement.
Like many other programming languages, VBScript uses variables to reserve memory
to store data and to name that memory location.
A variable must be declared with a name and a specific data type.
Since VBScript supports only one data type, Variant, all variables will be declared as Variant by default.
Here are some rules on variable declaration:
1. Explicit Declaration - A variable is declared with the "Dim" statement in the following syntax:
Dim variable_name, ...
where "variable_name" is a text label to identify this variable.
Multiple variables can be declared with single "Dim" statement.
The data type of this variable will be Variant.
Note that, in Visual Basic, you are allowed to specify a specific data type
in the Dim statement, because multiple data types are supported in Visual Basic.
So the following statement is valid in Visual Basic:
Dim author As String ' Allowed in Visual Basic
But in VBScript, you are not allowed to specify the data type in a Dim statement.
So statements below are not valid in VBScript:
Dim author As String ' Not allowed in VBScript
Dim buffer As Variant ' Not allowed in VBScript
2. Implicit Declaration - A variable name is used on the left side of an assignment statement without
being declared previously. The data type of an implicitly declared variable is "Variant".
Here are some examples of variable implicit declaration:
author = "Herong" ' Implicit declaration of "author"
buffer = 1/3 ' Implicit declaration of "buffer"
Just in case you want to know, "Dim" stands for "Dimension".
Some rules about variable names:
A variable name must begin with an alphabetic character.
For example, "price" is a valid variable name. But "$price" is not a valid variable name.
The dot character (.) can not be used in a variable name.
For example, "my.price" is not a valid variable name.
Variable names are case insensitive.
For example, "author" and "Author" are the same variable name.
VBScript reserved keywords can not be used as variable names.
For example, "empty" can not be used as a variable name.