Description
Returns a value indicating the subtype of a variable.
Syntax
VarType(varname)
The varname named argument can be any variable except a variable of a user-defined type.
Return Values
Value Returned |
Constant |
Variable Type |
0 |
vbEmpty |
Empty (uninitialized). |
1 |
vbNull |
Null (no valid data). |
2 |
vbInteger |
Integer. |
3 |
vbLong |
Long integer. |
4 |
vbSingle |
Single-precision floating point number. |
5 |
vbDouble |
Double-precision floating point number. |
6 |
vbCurrency |
Currency. |
7 |
vbDate |
Date. |
8 |
vbString |
String. |
9 |
vbObject |
OLE Automation object. |
10 |
vbError |
Error. |
11 |
vbBoolean |
Boolean. |
12 |
vbVariant |
Variant (used only with arrays of Variants). |
13 |
vbDataobject |
Non-OLE Automation object. |
8192 |
vbArray |
Array. |
Note
These constants are specified by Visual Basic. As a result, the names can be used anywhere in your code in place of the actual values.
Remarks
The VarType function never returns the value for vbArray by itself. It is always added to some other value to indicate an array of a particular type. The constant vbVariant is only returned in conjunction with vbArray to indicate that the argument to the VarType function is an array of type Variant. For example, the value returned for an array of integers is calculated as vbInteger + vbArray, or 8194.
See Also
Data Type Summary, IsArray Function, IsDate Function, IsEmpty Function, IsError Function, IsMissing Function, IsNull Function, IsNumeric Function, IsObject Function, TypeName Function, Variant Data Type.
Example
This example uses VarType to determine the subtype of a variable.
' Initialize variables. IntVar = 459: StrVar = "Hello World": DateVar = #2/12/69# MyCheck = VarType(IntVar) ' Returns 2. MyCheck = VarType(DateVar) ' Returns 7. MyCheck = VarType(StrVar) ' Returns 8.