Name
VarType Function
Syntax
VarType(varname)varnameUse: 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
varnameis 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 IfAlternatively, 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access