Variables
Variable is a named memory location used to hold a value that can be changed during the expression.
VBScript has only ONE fundamental data type, Variant.
A Variant can hold a String, a Number, a Date, or a Boolean.
Rules for Declaring Variables:
- Variable Name must begin with an alphabet.
- Variable names cannot exceed 255 characters.
-
Variables Should NOT contain a period(.)
-
Variable Names should be unique in the declared context.
Declaring Variables
Variables are declared using “dim” keyword. Since there is only ONE fundamental data type, all the declared variables are variant by default. Hence, user NEED NOT mention the type of data during declaration.
Example
Dim Var
Example
Each variable must be on its own separate line, for example:
Dim Variable1
Dim Variable2
Assigning Values to the Variables
Values are assigned similar to an algebraic expression. The variable name on the left hand side followed by an equal to (=) symbol and then its value on the right hand side.
RULES
- The numeric values should be declared without double quotes.
- The String values should be enclosed within doublequotes(") · Date and Time variables should be enclosed within hash symbol(#)
Examples
' Below Example, The value 25 is assigned to the variable.
Value1 = 25
' A String Value ‘VBScript’ is assigned to the variable StrValue.
StrValue = “VBScript”
' A Boolean Value False is assigned to the variable BoolValue.
BoolValue = False
' The date 01/01/2020 is assigned to the variable DToday.
Date1 = #01/01/2020#
' A Specific Time Stamp is assigned to a variable in the below example. Time1 = #12:30:44 PM#
Scope of the Variables
All variables are local to the expression they are executed.