VarType Function

   
VarType Function

Class

Microsoft.VisualBasic.Information

Syntax

 VarType(   varname   ) 
varname (required; any)

The name of a variable

Return Value

A member of the VariantType enumeration indicating the variable type

Description

Determines the data type of a variable

Rules at a Glance

  • The possible values returned by the function include the following members of the VariantType enumeration:

Constant

Value

Description

 Array 

8192

Array

 Boolean 

11

Boolean data type

 Byte 

17

Byte data type

 Char 

18

Char data type

 Date 

7

Date data type

 Decimal 

14

Decimal data type

 Double 

5

Double data type

 Integer 

3

Integer data type

 Long 

20

Long data type

 Object 

9

Object, uninitialized string, uninitialized array, object of a specific type

 Short 

2

Short data type

 Single 

4

Single data type

 String 

8

String

 UserDefinedType 

36

A structure

  • If varname is a dimensioned array, the VarTyp e function returns VariantType.Array (8192), plus the value of the array's data type. For example, an array of strings returns 8192 + 8 = 8200 . You can test for an array with a code fragment such as the following:

     If VarType(myVar) And VariantType.Array Then 

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

     vartype(myVar) and &HFFFFDFFF 
  • All object variables , whether late-bound or early-bound, return VariantType.Object .

  • Data types that are members of the base class library but are not wrapped by VB data types (i.e., UINT16, UINT32 etc.) return VariantType.UserDefinedType .

VB.NET/VB 6 Differences

  • In VB 6, passing a user -defined type as an argument to the VarType function generated an error. VB.NET allows you to pass a structure as an argument to the function.

  • In VB 6, the Vartype function indicates that the data type of an object is the data type of its default property. In VB.NET, all objects, including objects (like Collection objects) that have default properties, return VariantType. Object .

See Also

TypeName Function

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

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