VarType (function)

Syntax

VarType(variable)

Description

Returns an Integer representing the type of data in variable.

Comments

The variable parameter is the name of any Variant.

The following table shows the different values that can be returned by VarType:

 

Value

Constant

Data Type

 

0

ebEmpty

Uninitialized

 

1

ebNull

No valid data

 

2

ebInteger

Integer

 

3

ebLong

Long

 

4

ebSingle

Single

 

5

ebDouble

Double

 

6

ebCurrency

Currency

 

7

ebDate

Date

 

8

ebString

String

 

9

ebObject

Object (OLE automation object)

 

10

ebError

User-defined error

 

11

ebBoolean

Boolean

 

12

ebVariant

Variant (not returned by this function)

 

13

ebDataObject

Non-OLE automation object

Comments

When passed an object, the VarType function returns the type of the default property of that object. If the object has no default property, then either ebObject or ebDataObject is returned, depending on the type of variable.

Example

Sub Main()
  Dim v As Variant
  v = 5&          'Set v to a Long.

  If VarType(v) = ebInteger Then
    Msgbox "v is an Integer."
  ElseIf VarType(v) = ebLong Then
    Msgbox "v is a Long."
  End If
End Sub

See Also

Empty (constant); Null (constant); Variant (data type).

 

 

 

More information

V