VarType Function


VarType Function

Class

Microsoft.VisualBasic.Information

Syntax

     Dim result As VariantType = VarType(varName) 


varName (required; any)

The variable, instance, or expression to test

Description

The VarType function indicates the data type of an expression or instance, returning one of the following Microsoft.VisualBasic.VariantType enumeration values. Visual Basic also defines intrinsic constants for many of the members.

Enumeration value

Intrinsic constant

Description

Array

vbArray

An array of data.

Boolean

vbBoolean

Boolean data type (TRue or False).

Byte

vbByte

Byte data type.

Char

vbChar

Char data type.

Currency

vbCurrency

Currency data type. This entry is for backward compatibility. The .NET Decimal data type replaces the VB 6 Currency data subtype.

DataObject

 

Data objects.

Date

vbDate

Date data type.

Decimal

vbDecimal

Decimal data type.

Double

vbDecimal

Double data type.

Empty

vbEmpty

Null reference.

Error

 

System.Exception instance.

Integer

vbInteger

Integer data type.

Long

vbLong

Long data type.

Null

vbNull

Null object; DBNull.

Object

vbObject

Object, uninitialized string, uninitialized array, object of a nonspecific type; Nothing.

Short

 

Short data type.

Single

vbSingle

Single data type.

String

vbString

String data type.

UserDefinedType

vbUserDefinedType

A structure instance.

Variant

vbVariant

Variant data type. This entry is for backward compatibility. The .NET Object data type replaces the VB 6 Variant data type.


Usage at a Glance

  • If varName is a dimensioned array, the VarType function returns VariantType.Array and the data type of the array elements, combined using a bitwise Or operation. You can test for an array with a code fragment, such as the following:

         If ((VarType(someVariable) And VariantType.Array) = _        VariantType.Array) Then 

    You can extract the data type of the array with the following code fragment:

         VarType(someVariable) And Not VariantType.Array 

  • All object variables, whether late bound or early bound, return VariantType.Object.

  • Data types that are members of the base class library but do not directly map to one of the core data types listed in the VariantType enumeration (such as UInt16 or even UInteger) return VariantType.UserDefinedType.

Version Differences

  • You could not pass a user-defined data type to VarType in VB 6. This use is supported in .NET.

  • In VB 6, using the VarType function on an object returned the data type of its default property. In .NET, all objects, including objects that have default properties, return VariantType.Object.

See Also

TypeName Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net