VBScript Variables
A variable is a name given to a particular area in memory that stores a value, which can later be reused. When naming variables in VBScript it should be noted that the names are not case sensitive. Variable names must start with a letter, but can then be followed by either letters, numbers or underscores and cannot exceed 255 characters in length. One further restriction is that a variable name cannot be the same as a reserved word, or keyword, as they are sometimes known. Reserved words are those that have a specific purpose in VBScript and therefore cannot be used for anything else.
When declaring a variable, the ‘Dim’ reserved word is used. Unlike with a number of other languages, it is not necessary to specify the type of data that is to be assigned.
Dim variable_name
Once a variable has been declared, a value can be assigned to it.
variable_name = value
Variable declaration and assignment must be done separately in VBScript, the two processes cannot be combined, unlike with a number of other languages.
Below are some examples of variable declaration and assignment, the last of which contains a boolean value, that can either be ‘True’ or ‘False’.
' Variable declaration. Dim firstName Dim age Dim price Dim result ' Variable assignment. firstName = "Fred" ' String value. age = 30 ' Integer value. price = 12.99 ' Floating point or decimal value. result = True ' Boolean "True" or "False" value.