VBScript Select Case

The Select Case statement can be used instead of an If statement if you have many conditions to check for.

In the previous lesson, we used an Elseif statement to perform multiple checks against the value of a variable. VBScript Select Case statements are a more efficient way of doing this.

A Select Case statement allows us to perform multiple tests, with less code (and less computing power). This can be especially beneficial when you have many cases to test for.

Example Select Case Statement

This results in:

Same as the canary

Limitations of Select Case

Now, you may be thinking, "if Select Case is so efficient, why use If Elseif at all?".

Although the Select Case statement is more efficient than an If Elseif statement for this type of thing, it is somewhat limited - there may be times that you need to use an If Elseif statement. For example, the Select Case statement only allows you to check if a variable is equal to a value - you can't test to see if it is greater than, less than etc. Also, you can only test against one variable. If you have multiple variables to test against, you'll need to use an If statement.