|Lessons||VBScript Select Case Statement|
A Select Case statement allows us to perform multiple tests, with fewer lines of code.
favFruit = "Mango"
Select Case favFruit
document.write("My favorite fruit is Orange")
document.write("My favorite fruit is Mango")
document.write("My favorite fruit is Apple")
document.write("My favorite fruit is not available!")
Here is the output:
My favorite fruit is Mango
In the above code we assign the value Mango to the variable named favFruit and then use the same variable with the Select Case to search for the code block whose Case value matches the value of our variable favFruit. Once the block is found, code inside that block gets executed and the control transfers to the line immediately after the End Select words. The special, optional, Case Else code block is executed if a matching Select Case is not found. Important points about the Select Case Statement
The Select Case statement only allows us to check if a variable is equal to a value. We cannot make greater and / or less than type checks.
We can only test against one variable. For testing multiple variables we need to use the If statement.
Next >>> Lesson No. 11: VBScript While Loop