Name
VarType Function
Class
Microsoft.VisualBasic.Information
Syntax
VarType(varname)-
varname Use: Required
Data Type: Any
The name of a variable
Return Value
A member of the
VariantType
enumeration indicating the variable
type
Description
Determines the data type of a variable
Rules at a Glance
The possible values returned by the function include the following members of the
VariantTypeenumeration.Constant
Value
Description
Array8192
Array
Boolean11
Boolean data type
Byte17
Byte data type
Char18
Char data type
Date7
Date data type
Decimal14
Decimal data type
Double5
Double data type
Integer3
Integer data type
Long20
Long data type
Object9
Object, uninitialized string, uninitialized array, object of a specific type
Short2
Short data type
Single4
Single data type
String8
String
UserDefinedType36
A structure
If
varnameis a dimensioned array, theVarType function returnsVariantType.Array(8192), plus the value of the array’s data type. For example, an array of strings returns8192+8=8200. You can test for an array with a code fragment such as the following:If VarType(myVar) And VariantType.Array Then
You can extract the data type of the array with the following code fragment:
vartype(myVar) and &HFFFFDFFF
All object variables, whether late-bound or early-bound, return
VariantType.Object.Data types that are members of the base class library but are not wrapped by VB data types (i.e., UINT16, UINT32, ...
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