Visual Basic Language Reference  

TypeName Function

Returns a String value containing data type information about a variable.

Public Function TypeName(ByVal VarName As Object) As String

Parameter

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

Remarks

The following table shows the String values returned by TypeName for different contents of VarName.

VarName contents String returned
16-bit True or False value type "Boolean"
8-bit binary value type "Byte"
16-bit character value type "Char"
64-bit date and time value type "Date"
Reference type indicating missing or nonexistent data "DBNull"
128-bit fixed point numeric value type "Decimal"
64-bit floating point numeric value type "Double"
32-bit integer value type "Integer"
Reference type pointing to an unspecialized object "Object"
Reference type pointing to a specialized object created from class <objectclass> "<objectclass>"
64-bit integer value type "Long"
Reference type with no object currently assigned to it "Nothing"
16-bit integer value type "Short"
32-bit floating point numeric value type "Single"
Reference type pointing to a string of 16-bit characters "String"

If VarName is an array, the returned string can be any one of the strings in the preceding table with empty parentheses appended. For example, if VarName points to an array of integers, TypeName returns "Integer()".

When TypeName returns the name of a reference type such as a class, it only returns the simple name, not the qualified name. For example, if VarName points to an object of class System.Drawing.Printing.PaperSource, TypeName returns "PaperSource".

Example

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

Dim MyType As String
Dim StrVar As String = "MyString"
Dim DecVar As Decimal
Dim IntVar, ArrayVar(5) As Integer
MyType = TypeName(StrVar)   ' Returns "String".
MyType = TypeName(IntVar)   ' Returns "Integer".
MyType = TypeName(ArrayVar)   ' Returns "Integer()".

See Also

Data Type Summary | IsArray Function | IsDate Function | IsDBNull Function | IsError Function | IsNothing Function | IsNumeric Function | IsReference Function | Object Data Type