Multiple select cases in VB.NET

user1295053 picture user1295053 · Dec 20, 2012 · Viewed 34.4k times · Source

I have tried the below:

Select Case Combo1.SelectedItem Or Combo2.SelectedItem

But I get the error:

Conversion from String "string here" to type 'Long' is not valid

Is it possible to have multiple select cases?

Answer

Guffa picture Guffa · Dec 20, 2012

You separate multiple values by using a comma:

Case Combo1.SelectedItem, Combo2.SelectedItem

Using Or would make it an expression that would be evaluated before compared to the value in the Select.

If your value in the Select is a Long value, then you may need to convert the strings from the controls:

Case CLng(Combo1.SelectedItem), CLng(Combo2.SelectedItem)

To address the question directly, using multiple values as a test expression in a select is not possible:

Select Case v1, v2 'Not possible