VarType Function

See AlsoU2LTWU              Example23MLKZO>Low

Returns a value that indicates how a Variant8PHEAW3 is stored internally by Visual Basic.

Syntax

VarType(variant)

Remarks

The argument variant is a variable of the Variant data type3GYXY7.  The VarType function returns a value that provides information about the type of data stored in the Variant.

The value returned by VarType is one of the following:

 

Symbolic constant

Value

Meaning

 

V_EMPTY

 

Empty1L2JEZ4

V_NULL

 

Null1DDW7C0

V_INTEGER

 

Integer

V_LONG

 

Long

V_SINGLE

 

Single

V_DOUBLE

 

Double

V_CURRENCY

 

Currency

V_DATE

 

Date

V_STRING

 

String

 

 

Note   Symbolic constants for file Variant definitions can be found in the Visual Basic file CONSTANT.TXT.  When placed in any module in a project, the symbolic names can be used in all your form and code modules.

 


See Also

Data Types2M0APUD

IsDate Function9B784K

IsEmpty Function2K1M5H0

IsNull Function9BAKWR

IsNumeric Function1MXC66A


VarType Function Example

The example uses VarType to determine whether a Variant argument passed to the function is either a Single or a Double.  True is returned if the argument is one of these types of data, False if it is not.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Num                               ' Declare variable.

   Num = InputBox("Enter a number.")     ' Get number from user.

   If IsNumeric(Num) Then

      Num = CDbl(Num)

   Else

      MsgBox "You did not enter a number."

      Exit Sub

   End If

   If IsReal(Num) Then

      MsgBox "What you entered is a real number."

   Else

      MsgBox "What you entered is not a real number."

   End If

End Sub

Function IsReal(VarArg)

   If VarType(VarArg) = 4 Or VarType(VarArg) = 5 Then

      IsReal = True                      ' If Single or Double.

   Else

      IsReal = False                     ' If not.

   End If

End Function