Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Still thinking about VbTypeName - and hey, what's this...

I still couldn't get my mind off of the VbTypeName function this morning - I really need to start re-reading some of the VB Language Reference again I think!

Anyways, I thought that I'd punch out some code to highlight some returns from that function:

Dim t As Type
Dim objects() As Object = {System.DateTime.Now, 1S, 1I, 1L, 1.0R, 1D, New Object, CByte(&H34), "1"c}
For Each o As Object In objects
    t = o.GetType
    Response.Write("-> " & VbTypeName(t.Name) & "<br>") 
Next

'-> Date
'-> Short
'-> Integer
'-> Long
'-> Double
'-> Decimal
'-> Object
'-> Byte
'-> Char

Another interesting - although not likely to be used that often - language member is SystemTypeName. Here's what the docco has to say about this guy:

returns the fully qualified common language runtime type name corresponding to the Visual Basic type name

So, to see the relationship that it has with some other Type related methods/functions:

For Each o As Object In objects
    t = o.GetType
    Response.Write("-> " & t.Name & " : " & SystemTypeName(VbTypeName(t.Name)) & "<br>")
Next

'-> DateTime : System.DateTime
'-> Int16 : System.Int16
'-> Int32 : System.Int32
'-> Int64 : System.Int64
'-> Double : System.Double
'-> Decimal : System.Decimal
'-> Object : System.Object
'-> Byte : System.Byte
'-> Char : System.Char

So, all of that effectively means that
    TypeName(x)
is the equivalent of
    vbTypeName( SystemTypeName(x) )

No Comments