TypeName Function (Visual Basic)
Returns a String value containing data-type information about a variable.
Public Function TypeName(ByVal VarName As Object) As String
Parameters
- 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" |
8-bit signed integer value type |
"SByte" |
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" |
32-bit unsigned integer value type |
"UInteger" |
64-bit unsigned integer value type |
"ULong" |
16-bit unsigned integer value type |
"UShort" |
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".
Example
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()".
Requirements
Namespace: Microsoft.VisualBasic
Module: Information
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
See Also
Reference
Data Type Summary (Visual Basic)
IsArray Function (Visual Basic)
IsDate Function (Visual Basic)