TypeOf Operator


TypeOf Operator

Syntax

     Dim result As Boolean = TypeOf   varName Is typeName 

or:

     Dim result As Boolean = TypeOf varName IsNot typeName 


varName (required; any)

The variable, instance, or expression to compare with a data type


typeName (required)

The class, interface, structure, or other type name against which to compare varName

Description

The TypeOf operator indicates whether an instance of data is of a specific type (true) or not (False). It is always used with the Is or IsNot keyword, followed by a valid .NET type. It is most often used with If...Then...Else statements, as in:

     If (TypeOf someVariable Is Integer) Then        ' ----- Integer-specific code here.     End If 

New in 2005. Visual Basic 2005 introduced a new IsNot keyword that negates the Boolean result of the TypeOf operator.

     If (TypeOf someVariable IsNot Integer) Then        ' ----- Non-Integer-specific code here.     End If 

Before 2005, the equivalent of this syntax required the use of the Not operator.

     If Not (TypeOf someVariable Is Integer) Then        ' ----- Non-Integer-specific code here.     End If 

Version Differences

Visual Basic 2005 includes a new IsNot keyword. It was not available in earlier versions of VB for .NET or in VB 6.

See Also

Is Operator, IsNot Operator




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