Name
VarType Function
Syntax
VarType(varname
)
varname
Use: Required
The name of a variable.
Return Value
An Integer representing the data type of
varname
.
Description
Determines the data type of a specified variable.
Rules at a Glance
The following intrinsic constants can test the return value of the VarType function:
Constant | Value | Data type |
| 11 | Boolean |
| 17 | Byte |
| 6 | Currency |
| 13 | A data access object variable |
| 7 | Date |
| 14 | Decimal |
| 5 | Double-precision floating-point number |
| 0 | Uninitialized |
| 10 | An error type that indicates a missing argument |
| 2 | Integer |
| 3 | Long integer |
| 1 | No valid data |
| 9 | A generic object |
| 4 | Single-precision floating-point number |
| 8 | String |
| 12 | Variant—returned only with |
If
varname
is an array created by VBScript code, the VarType function returns 8200 (vbArray
) andvbVariant
.If varname is an array returned to the script by a component, the VarType function returns 8200 (
vbArray)
and the value representing the data type of the array. For instance, a Visual Basic Integer array returned to a VBScript script produces a value of8196(vbInteger + vbArray).
To test for an array, you can use the intrinsic constant
vbArray
. For example:If VarType(myVar) And vbArray Then MsgBox "This is an array" End If
Alternatively, you can also use the IsArray function.
Programming Tips and Gotchas
When you use VarType with an object variable, you may get what appears to be an incorrect ...
Get VBScript in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.