VarType Function

Description

Returns a value indicating the subtype of a variable.

Syntax

VarType(varname)

The varname argument can be any variable except a variable of a user-defined type.

Return Values

Constant

Value

Variable type description

vbEmpty

0

Empty (uninitialized)

vbNull

1

Null (no valid data)

vbInteger

2

Integer

vbLong

3

Long integer

vbSingle

4

Single-precision floating-point number

vbDouble

5

Double-precision floating-point number

vbCurrency

6

Currency

vbDate

7

Date

vbString

8

String

vbObject

9

OLE Automation object

vbError

10

Error

vbBoolean

11

Boolean

vbVariant

12

Variant (used only with arrays of Variants)

vbDataObject

13

Non-OLE Automation object

vbByte

17

Byte

vbArray

8192

Array


Note These constants are specified by Visual Basic for applications. 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. If an object has a default property, VarType (object) returns the type of its default property.

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 the VarType function to determine the subtype of a variable.


' Initialize variables.= 459: StrVar = "Hello World": DateVar = #2/12/69# = VarType(IntVar)                ' Returns 2.= VarType(DateVar)                ' Returns 7.= VarType(StrVar)                ' Returns 8.