|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
select case TypeSelect 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 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 When checking for specific types, I would use a ElseIf as it ensures that | long list? 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 -- Show quoteHide quoteHope 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 | | 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 > | > | > > 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. -- Show quoteHide quoteHope 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: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 | > | | > | | > | > | | "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/> 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 >
A (not so) basic question.
Detect if virusscanner is installed current function / sub name ? Cal Dll was written by VC++ in VB receiving data over socket Obtain contents of an external listview and/or treeview breaking up strings Datagrid scrollbar filtering which files can be opened ¿How can I to get the time of execution of an application? |
|||||||||||||||||||||||