VarType Function

Syntax

VarType(var)

Group

Variable Info

Description

Return a number indicating the type of value stored in var.

Parameters

Parameters Description
var Return a number indicating the type of value stored in this variable.

 

Result Value Description
vbEmpty 0 Variant variable is Empty. It has never been assigned a value.
vbNull 1 Variant variable is null.
vbInteger 2 Variable contains an Integer value. The value depends on the #Language setting.
vbLong 3 Variable contains a Long value. The value depends on the #Language setting.
vbSingle 4 Variable contains a Single value.
vbDouble 5 Variable contains a Double value.
vbCurrency 6 Variable contains a Currency value.
vbDate 7 Variable contains a Date value.
vbString 8 Variable contains a String value.
vbObject 9 Variable contains an Object reference. If the object reference supports a default property the VarType of the default property's value is returned instead of vbObject.
vbError 10 Variable contains a error code value.
vbBoolean 11 Variable contains a Boolean value.
vbVariant 12 Variable contains a variant value. (Only used for arrays of variants.)
vbDataObject 13 Variable contains a non-ActiveX Automation object reference.
vbDecimal 14 Variable contains a Decimal value.
vbSByte 16 Variable contains a SByte value.
vbByte 17 Variable contains a Byte value.
vbUInteger 18 Variable contains a UInteger value. The value depends on the #Language setting.
vbULong 19 Variable contains a ULong value. The value depends on the #Language setting.
vbHuge_ 20 Variable contains a Huge_ value.
vbUHuge_ 21 Variable contains a UHuge_ value.
vbUserDefinedType 36 Variable contains a User Defined Type value.
+vbArray 8192 Variable contains an array value. Use VarType( ) And 255 to get the type of element stored in the array.

Example


Sub Main
    Dim X As Variant
    Debug.Print VarType(X) ' 0
    X = 1
    Debug.Print VarType(X) ' 2
    X = 100000
    Debug.Print VarType(X) ' 3
    X = 1.1
    Debug.Print VarType(X) ' 5
    X = "A"
    Debug.Print VarType(X) ' 8
    Set X = CreateObject("Word.Basic")
    Debug.Print VarType(X) ' 9
    X = Array(0,1,2)
    Debug.Print VarType(X) ' 8204 (8192+12)
End Sub

See also

TypeName