schizoid04
schizoid04

Reputation: 934

Vb.NET - ' Case "String1" Or "String2" ' trying to convert "String2" to Long

A section of code I was updating used a select case statement to compare the value of a string...

I noticed that for two possible values, I could end up re-using the same bit of code.

So I added a case:

Case "Yes/No" Or "Continue"

However, when I reached this point, I'd throw an invalid cast exception.

The exception said it was trying to cast "Yes/No" as a Long value instead of a string.

Taking 'Or "Continue" ' and moving it to it's own case statement with a duplicated section of code resolved the issue.

I'm trying to find out why "Yes/No" Or "Continue" didn't work out the way I'd expected.

I was under the impression that I could write out an expression there similar to the way I could when writing an If statement.

Upvotes: 1

Views: 656

Answers (1)

David BS
David BS

Reputation: 1892

SUbstitute the word OR for comma. Ex. Case "Yes/No", "Continue"

Upvotes: 5

Related Questions