multiple contitions for select case

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

hi,

id like to know how, if it is possible, to check for multiple conditions in a VB/VBScript select case statement.

eg

select SomeThing AND AnotherThing
case SomeThing=1 AND AnotherThing=2
blah
case SomeThing=3 AND AnotherThing=7
blah
end select

etc.

im trying to avoid using excessive if statements to do this. select is easier to understand Laughing out loud. ive tried variations of the above psuedo but to no avail. any help is appreciated.

thanks Laughing out loud

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

I don't think that's possible, you could try nesting your Select statements like:

Select Case SomeThing
Case 1
Select Case AnotherThing
Case 2
'some code
End Select
Case 3
Select Case AnotherThing
Case 7
'some code
End Select
End Select

PJ | Are we there yet?
pjboettcher.com

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

That's one of the things I never liked about VB.

With C style langues, you can do stuff like this:

switch case ($var) {
    case 1:
    case 2:
        # do foo
        break;
    default:
        # do bar
        break;
}
'If $var is 1 or 2, it will do foo, else it will do bar. Why Microsoft, in it's infinite wisdom, could not come up with an equal is beyond me.

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.