VBScript has only one data type called a variant. A Variant is a special data type that can contain different kinds of information, depending on how it is used.
It is important to note that VBScript will automatically change the data type of a variable as soon as the variable is assigned.
Note: All functions in VBScript return the data type Variant.
The following table lists the data types a Variant can contain:
|Empty||Variant is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables.|
|Null||Variant intentionally contains no valid data.|
|Boolean||Contains either True or False.|
|Byte||Contains integer in the range 0 to 255.|
|Integer||Contains integer in the range -32,768 to 32,767.|
|Currency||-922,337,203,685,477.5808 to 922,337,203,685,477.5807.|
|Long||Contains integer in the range -2,147,483,648 to 2,147,483,647.|
|Single||Contains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.|
|Double||Contains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.|
|Date (Time)||Contains a number that represents a date between January 1, 100 to December 31, 9999.|
|String||Contains a variable-length string that can be up to approximately 2 billion characters in length.|
|Object||Contains an object.|
|Error||Contains an error number.|
Identifying Variable Types
The data type of a variable can be examined by using either of two VBScript functions:
- TypeName - returns the name of the data type
- VarType - returns the VBScript number representing the data type
The following example demonstrates the changing data type:
Dim v Msgbox(TypeName(v)) 'Returns Empty v = 1 Msgbox(TypeName(v)) 'Returns Integer v = 1234567 Msgbox(TypeName(v)) 'Returns Long v = 123.45 Msgbox(TypeName(v)) 'Returns Double v = "Hello from VBScript" Msgbox(TypeName(v)) 'Returns String