TypeName Function


TypeName Function

Class

Microsoft.VisualBasic.Information

Syntax

     Dim result As String = TypeName(varName) 


varName (required; any)

The variable, instance, or expression to assess

Description

The TypeName function returns the name of the data type for varName. The possible return values are:

String returned

Variable contents

Boolean

Boolean value (true or False)

Byte

8-bit binary value

Char

16-bit character value

Date

64-bit date and time value

DBNull

Missing or nonexistent data

Decimal

96-bit fixed point numeric value

Double

64-bit floating point numeric value

Integer

32-bit integer value

Long

64-bit integer value type

Nothing

Object with no instance; uninitialized string; undimensioned array

Object

Unspecialized object; instance of System.Object

Short

16-bit integer value

Single

32-bit floating point numeric value

String

String of 16-bit characters


Anything else

The name of the class or structure used to create an instance of varName

Usage at a Glance

  • If varName is an array, the returned name is followed by a set of empty parentheses, as in "Integer( )."

  • This function returns the immediate type used for varName; it does not return the derived class name. If it did, the function would always return "Object."

  • Only the type name is returned by TypeName; the namespace is not included.

Example

     Dim genericObject As Object     genericObject = New Employee     MsgBox(TypeName(genericObject))     ' Displays: Employee     genericObject = 100     MsgBox(TypeName(genericObject))     ' Displays: Integer     genericObject = Nothing     MsgBox(TypeName(genericObject))     ' Displays: Nothing 

Version Differences

  • In VB 6, the following code fragment:

         Dim strVar As String     MsgBox(TypeName(strVar)) 

    returns "String." In .NET, this same code displays "Nothing," since the string has not yet been assigned an instance.

  • In VB 6, TypeName cannot be used with user-defined data types; this use is supported in .NET.

  • In VB 6, passing an uninitialized array to the TypeName function returns the type name plus parentheses. In .NET, it returns "Nothing."

  • In VB 6, a variable with a type that is not declared is reported as "Variant;" in .NET, it is "Object."

See Also

VarType 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