VarType Function |
No
VarType(varname)
varname
Use: Required
The name of a variable.
An integer representing the data type of varname.
Determines the data type of a specified variable.
The VarType function can't be used with user-defined types.
The following intrinsic constants can test the return value of the VarType function:
Constant | Value | Data Type or Variant Value |
---|---|---|
vbArray | 8192 | Array |
vbBoolean | 11 | Boolean |
vbByte | 17 | Byte |
vbCurrency | 6 | Currency |
vbDataObject | 13 | A data access object variable |
vbDate | 7 | Date |
vbDecimal | 14 | Decimal |
vbDouble | 5 | Double-precision floating-point number |
vbEmpty | 0 | Uninitialized variant |
vbError | 10 | An error |
vbInteger | 2 | Integer |
vbLong | 3 | Long integer |
vbNull | 1 | No valid data |
vbObject | 9 | Variable explicitly declared as type Object |
vbSingle | 4 | Single-precision floating-point number |
vbString | 8 | String |
cbUserDefinedType | 36 | User-defined type |
vbVariant | 12 | Variant—only returned with vbArray (8192) |
If varname is an array, the VarType function returns 8192 (vbArray) plus the value of the data type of the array. For example, an array of strings returns 8192 + 8 = 8200. 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
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 data type of the default property.