Home All Groups Group Topic Archive Search About
Author
28 May 2006 3:38 PM
PJ6
Select Case o.GetType
    Case = GetType(SomeRandomTypeName)
    '...
End Select

Why doesn't this work? Can I make it work or am I stuck with ElseIf for a
long list?

Paul

Author
28 May 2006 4:22 PM
Jay B. Harlow [MVP - Outlook]
Paul,
| Why doesn't this work?
Case requires "elementary data type". Type is not a "elementary", but rather
it is a class.

http://msdn2.microsoft.com/en-us/library/cy37t14y.aspx


| Can I make it work or am I stuck with ElseIf for a
| long list?
When checking for specific types, I would use a ElseIf as it ensures that
derived types are handled correctly.

You can get a select case to work, by using the type names, however then you
are limited to the type names & if you ever change the name of the type your
select case will break.

Something like:
| Select Case o.GetType.ToString
|    Case "SomeNameSpace.SomeRandomTypeName"
|    '...
| End Select


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"PJ6" <no***@nowhere.net> wrote in message
news:ulePazmgGHA.1320@TK2MSFTNGP04.phx.gbl...
| Select Case o.GetType
|    Case = GetType(SomeRandomTypeName)
|    '...
| End Select
|
| Why doesn't this work? Can I make it work or am I stuck with ElseIf for a
| long list?
|
| Paul
|
|
Author
28 May 2006 5:07 PM
PJ6
OK, but I don't see why they have that restriction, why the "Is" operator
here cannot function the same as the "Is" operator elsewhere. It would seem
to me an arbitrary and rather unnecessary break in convention.

Paul

Show quoteHide quote
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> wrote in
message news:uyRtuLngGHA.3456@TK2MSFTNGP05.phx.gbl...
> Paul,
> | Why doesn't this work?
> Case requires "elementary data type". Type is not a "elementary", but
> rather
> it is a class.
>
> http://msdn2.microsoft.com/en-us/library/cy37t14y.aspx
>
>
> | Can I make it work or am I stuck with ElseIf for a
> | long list?
> When checking for specific types, I would use a ElseIf as it ensures that
> derived types are handled correctly.
>
> You can get a select case to work, by using the type names, however then
> you
> are limited to the type names & if you ever change the name of the type
> your
> select case will break.
>
> Something like:
> | Select Case o.GetType.ToString
> |    Case "SomeNameSpace.SomeRandomTypeName"
> |    '...
> | End Select
>
>
> --
> Hope this helps
> Jay B. Harlow [MVP - Outlook]
> .NET Application Architect, Enthusiast, & Evangelist
> T.S. Bradley - http://www.tsbradley.net
>
>
> "PJ6" <no***@nowhere.net> wrote in message
> news:ulePazmgGHA.1320@TK2MSFTNGP04.phx.gbl...
> | Select Case o.GetType
> |    Case = GetType(SomeRandomTypeName)
> |    '...
> | End Select
> |
> | Why doesn't this work? Can I make it work or am I stuck with ElseIf for
> a
> | long list?
> |
> | Paul
> |
> |
>
>
Author
28 May 2006 6:39 PM
Jay B. Harlow [MVP - Outlook]
PJ6
There is no "Is" operator in a Select Case per se!

Notice that in a Select Case that "Is" is used to introduce a comparison
operator, such as <, >, <=, >=, =, or <>. That is "[Is] comparisonoperator".

IMHO: using "Case Is < 10" reads better then "Case < 10", however that is
largely personal preference.

Its similar to the "Is" keyword in the "TypeOf Is" operator.
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


Show quoteHide quote
"PJ6" <no***@nowhere.net> wrote in message
news:OhJm0kngGHA.1208@TK2MSFTNGP02.phx.gbl...
| OK, but I don't see why they have that restriction, why the "Is" operator
| here cannot function the same as the "Is" operator elsewhere. It would
seem
| to me an arbitrary and rather unnecessary break in convention.
|
| Paul
|
| "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_***@tsbradley.net> wrote in
| message news:uyRtuLngGHA.3456@TK2MSFTNGP05.phx.gbl...
| > Paul,
| > | Why doesn't this work?
| > Case requires "elementary data type". Type is not a "elementary", but
| > rather
| > it is a class.
| >
| > http://msdn2.microsoft.com/en-us/library/cy37t14y.aspx
| >
| >
| > | Can I make it work or am I stuck with ElseIf for a
| > | long list?
| > When checking for specific types, I would use a ElseIf as it ensures
that
| > derived types are handled correctly.
| >
| > You can get a select case to work, by using the type names, however then
| > you
| > are limited to the type names & if you ever change the name of the type
| > your
| > select case will break.
| >
| > Something like:
| > | Select Case o.GetType.ToString
| > |    Case "SomeNameSpace.SomeRandomTypeName"
| > |    '...
| > | End Select
| >
| >
| > --
| > Hope this helps
| > Jay B. Harlow [MVP - Outlook]
| > .NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley - http://www.tsbradley.net
| >
| >
| > "PJ6" <no***@nowhere.net> wrote in message
| > news:ulePazmgGHA.1320@TK2MSFTNGP04.phx.gbl...
| > | Select Case o.GetType
| > |    Case = GetType(SomeRandomTypeName)
| > |    '...
| > | End Select
| > |
| > | Why doesn't this work? Can I make it work or am I stuck with ElseIf
for
| > a
| > | long list?
| > |
| > | Paul
| > |
| > |
| >
| >
|
|
Author
28 May 2006 7:57 PM
Herfried K. Wagner [MVP]
"PJ6" <no***@nowhere.net> schrieb:
> Select Case o.GetType
>    Case = GetType(SomeRandomTypeName)
>    '...
> End Select
>
> Why doesn't this work? Can I make it work or am I stuck with ElseIf for a
> long list?


\\\
Dim t As Type = o.GetType()
Select Case True
    Case t Is GetType(SomeRandomTypeName)
        ...
    Case t Is GetType(...)
        ...
    ...
End Select
///

- or -

\\\
Select Case True
    Case TypeOf t Is SomeRandomType
        ...
    Case TypeOf t Is ...
        ...
    ...
End Select
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
1 Jun 2006 7:52 AM
Roland
I am using

Select case o.getType.name
    Case (SomerandomTypeName)
    Case ...
End Select

works as a charm since it is "o.getType.name" is a string
Roland

Show quoteHide quote
"PJ6" <no***@nowhere.net> wrote in message
news:ulePazmgGHA.1320@TK2MSFTNGP04.phx.gbl...
> Select Case o.GetType
>    Case = GetType(SomeRandomTypeName)
>    '...
> End Select
>
> Why doesn't this work? Can I make it work or am I stuck with ElseIf for a
> long list?
>
> Paul
>