VBScript VarType Function
Definition and Usage
The VarType function can return a value indicating the sub-type of the specified variable.
Values that the VarType function can return:
Constant | Value | Description |
---|---|---|
vbEmpty | 0 | Not initialized (default) |
vbNull | 1 | Does not contain any valid data |
vbInteger | 2 | Integer sub-type |
vbLong | 3 | Long integer sub-type |
vbSingle | 4 | Single precision sub-type |
vbDouble | 5 | Double precision sub-type |
vbCurrency | 6 | Currency sub-type |
vbDate | 7 | Date or Time value |
vbString | 8 | String Value |
vbObject | 9 | String Subtype |
vbError | 10 | Error Subtype |
vbBoolean | 11 | Boolean Subtype |
vbVariant | 12 | Variant (only for variable arrays) |
vbDataObject | 13 | Data Access Object |
vbDecimal | 14 | Decimal Subtype |
vbByte | 17 | Byte Subtype |
vbArray | 8192 | Array |
Note:These constants are specified by VBScript. Therefore, these names can be used anywhere in the code to represent actual values.
Note:If the variable is an array, VarType() will return 8192 + VarType(array element). For example, the VarType() of an integer array will return 8192 + 2 = 8194.
Syntax
VarType(varname)
Parameter | Description |
---|---|
varname | Required. The name of the variable. |
Example
dim x x="Hello World!" document.write(VarType(x)) x=4 document.write(VarType(x)) x=4.675 document.write(VarType(x)) x=Null document.write(VarType(x)) x=Empty document.write(VarType(x)) x=True document.write(VarType(x))
Output separately:
String Integer Double Null Empty Boolean