Select Case with Multiple Variables?

mattkw80

Well-known member
Joined
Jan 3, 2008
Messages
49
Location
Ontario, Canada
Programming Experience
Beginner
Is there any way to use a Select statement to Test multiple variables?

ie:

Dim x as integer = 1
Dim x as integer = 2
Dim z as integer = 3

Select Case x, y, z

case is 1, 2, 3

End Select
 
You could try something like :-

VB.NET:
    Select Case True
        Case x = 1 OrElse x = 2 OrElse x = 3 OrElse y = 1 OrElse y = 2 'etc
            'do work here
    End Select
 
You can also use the Linq Any method to determine if any of the variables matches any of a set of target values:
Dim x = 1, y = 2, z = 3
Dim variables() As Integer = {x, y, z}
Dim values() As Integer = {3, 4, 5}

Dim any As Boolean = variables.Any(Function(value) values.Contains(value))
 
Back
Top