Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

VarType Function

Returns an Integer value containing the data type classification of a variable.

Public Function VarType(ByVal VarName As Object) As VariantType


Required. Object variable. If Option Strict is Off, you can pass a variable of any data type except a structure.


The integer value returned by VarType is a member of the VariantType enumeration.

The following table shows the values returned by VarType for special cases of VarName.

Data type represented by VarName Value returned by VarType
Nothing VariantType.Object
DBNull VariantType.Null
Enumeration Underlying data type (Byte, Short, Integer, or Long)
Array Bitwise OR of array element type and VariantType.Array
Array of arrays Bitwise OR of VariantType.Object and VariantType.Array
Structure (System.ValueType) VariantType.UserDefinedType
System.Exception VariantType.Error
Unknown VariantType.Object


This example uses the VarType function to return data type classification information about several variables.

Dim MyString As String = "MyString"
Dim MyObject As Object
Dim MyNumber, MyArray(5) As Integer
Dim MyVarType As VariantType   ' Integer enumeration.
MyVarType = VarType(MyVarType)   ' Returns VariantType.Integer.
MyVarType = VarType(MyString)   ' Returns VariantType.String.
MyVarType = VarType(MyObject)   ' Returns VariantType.Object.
MyVarType = VarType(MyArray)   ' Returns the bitwise OR of 
                                     ' VariantType.Array and 
                                     ' VariantType.Integer.

Smart Device Developer Notes

This function is not supported.


Namespace: Microsoft.VisualBasic

Module: Information

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

See Also

Data Type Summary | Object Data Type | VariantType Enumeration

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.