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
VarTypefunction:
|
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
varnameis an array, theVarTypefunction 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 IfAlternatively, you can also use the
IsArrayfunction.
Programming Tips & Gotchas
When you use
VarTypewith 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,VarTypereturns the datatype of the default property.The
VarType ...
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