Home All Groups Group Topic Archive Search About

Having trouble comparing types...

Author
25 May 2006 4:20 PM
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.

Author
25 May 2006 5:23 PM
Kevin Spencer
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.

Show quote
"Mike Edgewood" <itm***@gmail.com> wrote in message
news:1148574013.660193.234450@y43g2000cwc.googlegroups.com...
>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.
>
Author
25 May 2006 6:18 PM
Mike Edgewood
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.
Author
25 May 2006 6:47 PM
Mike Edgewood
Ah Ha...

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

AddThis Social Bookmark Button