Having trouble comparing types...

  • Thread starter Thread starter Mike Edgewood
  • Start date Start date
M

Mike Edgewood

I want to compare types in a case statement.

ie.
Select Case dr(i).GetType
Case System.Double
' Double action here
Case System.Date
' Date Action Here
End Case


If dr(i).GetType is GetType(System.Double) Then...
... works fine here, but put it in a case statement and wavy
underlines appear.

Cannot seem to understand the correct systax for the case statement
usage in this scenario. Is this doable in a case statement? I'm
probably overlooking something simple, but just can't see it.
 
You can do this by getting the TypeCode of the type. This is available by
calling the Type.GetTypeCode method on the Type returned.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

This is, by definition, not that.
 
Still getting errors...
(where dr = sqldatareader; i = integer)

Select Case dr(i).GetTypeCode ' results in late binding error

... Case Double.GetTypeCode ' error: Reference to a non-Shared
member requires an object reference.

.... Case is Double.GetTypeCode ' error: Relational operator expected.
End Select

Case Is, Case =, Case Is =, all error out.

Select Case dr(0).GetType
Case Is = GetType(System.Double)
End Select ' Error: Operator "=" is not defined for types
'System.Type' and 'System.Type'.

Can you show me an example? It is the syntax I am not understanding
and an example would help me tremendously.
 
Ah Ha...

Select Case Type.GetTypeCode(dr(i).GetType)
Case TypeCode.Double
....
Case TypeCode.DateTime
....
End Select
 
Back
Top