Name
VarType Function
Syntax
VarType(varname
)
-
varname
Use: Required
The name of a variable.
Return Value
A Variant of subtype Integer representing the data subtype of
varname
.
Description
Determines the data subtype of a specified variable.
Rules at a Glance
The following intrinsic constants can test the return value of the
VarType
function:
Constant |
Value |
Datatype |
---|---|---|
|
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 |
|
2 |
Integer |
|
3 |
Long integer |
|
1 |
No valid data |
|
9 |
Variable explicitly declared as type Object |
|
4 |
Single-precision floating-point number |
|
8 |
String |
|
36 |
User-defined type |
|
12 |
Variant—returned only with |
If
varname
is an array, theVarType
function returns 8200 (vbArray
) andvbVariant
.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 & Gotchas
When you use
VarType
with an object variable, you may get what appears to be an incorrect return value. The reason for this is that if the object has a default property,VarType
returns the datatype of the default property.The
VarType ...
Get VBScript in a Nutshell 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.