[ASP.NET 2.0] Select Case

R

Rob Meade

Ok - I *think* this is only different in .net 2.0 - as I've not had any
problems in the past, but then maybe I've not tried it...

I have a value being read from an xml file where the value maybe a word or a
number, ie...

Low or 1
Medium or 2
High or 3

I have a select case statement as follows:

select case XMLTextReader.ReadInnerXml.ToLower

case "low" or "1"

case "medium" or "2"

case "high" or "3"

end select

as soon as I step past the "case low or 1" line it error with a message
about not being able to convert a string to a long...

If I do this:

select case XMLTextReader.ReadInnerXml.ToLower

case "1"

case "2"

case "3"

case "low"

case "medium"

case "high"

end select

it works fine - I dont understand?!

xmlReaderValue is declared as a string, the 1 is in quotes - thus a string
(right?).. so at which point does it think - oh yes - a long?

I even have a .ToLower on the end of the XMLTextReader.ReadInnerXml.ToLower
line so surely that would give some other kinda error if it wasn't a string?

Any help appreciated, I know I can do this a different way, but I'd like to
understand why this isn't working.

Cheers

Rob
 
R

Rob Meade

Oh, and I especially like the piece of IntelliSense help that says;

"When casting from a number, the value must be less than infinity" - hehe, I
started typing that number in - but got bored :eek:D

Rob
 
R

Rob Meade

I hate it when two minutes later I post an answer to my own question - damn
my lack of RTFM skills!

a comma instead of the word Or seems to do the trick...

"low", "1"
"medium", "2"

*sigh*

Rob
 
S

Scott M.

Have you tried this:

Select case XMLTextReader.ReadInnerXml.ToLower
Case "low", "1"

Case "medium", "2"

Case "high", "3"

End Select
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top