Share via

TypeName Function (Visual Basic)

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

Public Function TypeName(ByVal VarName As Object) As String


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


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


8-bit binary value type


16-bit character value type


64-bit date and time value type


Reference type indicating missing or nonexistent data


128-bit fixed-point numeric value type


64-bit floating-point numeric value type


32-bit integer value type


Reference type pointing to an unspecialized object


Reference type pointing to a specialized object created from class objectclass


64-bit integer value type


Reference type with no object currently assigned to it


8-bit signed integer value type


16-bit integer value type


32-bit floating-point numeric value type


Reference type pointing to a string of 16-bit characters


32-bit unsigned integer value type


64-bit unsigned integer value type


16-bit unsigned integer value type


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 returns only the name itself, not the qualified name. For example, if VarName points to an object of class System.Drawing.Printing.PaperSource, TypeName returns "PaperSource". Note that if the variable is declared to be of a certain class type but does not have an object assigned to it, TypeName returns "Nothing".


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

Dim testType As String 
Dim strVar As String = "String for testing" 
Dim decVar As Decimal 
Dim intVar, arrayVar(5) As Integer
testType = TypeName(strVar)
' The preceding call returns "String".
testType = TypeName(decVar)
' The preceding call returns "Decimal".
testType = TypeName(intVar)
' The preceding call returns "Integer".
testType = TypeName(arrayVar)
' The preceding call returns "Integer()".


Namespace: Microsoft.VisualBasic

Module: Information

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also


Data Type Summary (Visual Basic)

IsArray Function (Visual Basic)

IsDate Function (Visual Basic)

IsDBNull Function

IsError Function

IsNothing Function

IsNumeric Function (Visual Basic)

IsReference Function