Skip to content

VarType

Returns a VbVarType value identifying the subtype of a variable, or the type of an object's default property.

Syntax: VarType( varname )

varname
required A Variant containing any variable except a variable of a user-defined type.

The return value is one of the constants from the VbVarType enumeration, or the sum of one of those constants and vbArray. The most useful values are:

ConstantValueDescription
vbEmpty0Empty (uninitialized).
vbNull1Null (no valid data).
vbInteger2Integer.
vbLong3Long integer.
vbSingle4Single-precision floating-point number.
vbDouble5Double-precision floating-point number.
vbCurrency6Currency.
vbDate7Date.
vbString8String.
vbObject9Object reference.
vbError10Error value.
vbBoolean11Boolean.
vbVariant12Variant (used only with arrays of variants).
vbDecimal14Decimal.
vbByte17Byte.
vbLongLong20LongLong (64-bit only).
vbUserDefinedType36Variant containing a user-defined type.
vbArray8192Array. Always added to another value when returned.

If an object is passed and has a default property, VarType(object) returns the type of that default property.

VarType never returns vbArray by itself; it is always added to another value to indicate an array of a particular subtype. For example, an array of Integer returns vbInteger + vbArray, or 8194. The constant vbVariant is only returned in conjunction with vbArray, indicating an array of Variant.

INFO

twinBASIC also exposes a generic form, VarType(Of T), which is useful for compile-time verification of generic type specifiers. The non-generic call uses special internal bindings and so may not behave like a regular function.

Example

This example uses VarType to determine the subtype of several variables.

vb
Dim MyCheck As VbVarType
Dim IntVar As Integer, StrVar As String, DateVar As Date
Dim ArrayVar As Variant
IntVar = 459
StrVar = "Hello World"
DateVar = #2/12/1969#
ArrayVar = Array("1st Element", "2nd Element")

MyCheck = VarType(IntVar)             ' Returns 2  (vbInteger).
MyCheck = VarType(DateVar)            ' Returns 7  (vbDate).
MyCheck = VarType(StrVar)             ' Returns 8  (vbString).
MyCheck = VarType(ArrayVar)           ' Returns 8204 — vbArray + vbVariant.

See Also

twinBASIC and LOGO copyright of "WaynePhillipsEA" author