www.pickatutorial.com Computer Tutorials
Top eBooks: C/C++ | C# | Android | Mathematics | Database | Cloud | Graphics | Networking | Oracle | Hardware | AI
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons VBScript Select Case Statement Bookmark and Share
Tutorial Home
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
In the last two lessons we learned VBScript If statement and its different forms. In the last lesson we learned that the Elseif statement is used to check for multiple conditions. There is another construct available in VBScript called Select Case, that is a more elegant way of doing the same thing.

A Select Case statement allows us to perform multiple tests, with fewer lines of code.

Here is an example:

<script type="text/vbscript">
Dim favFruit
favFruit = "Mango"
Select Case favFruit
Case "Orange"
document.write("My favorite fruit is Orange")
Case "Mango"
document.write("My favorite fruit is Mango")
Case "Apple"
document.write("My favorite fruit is Apple")
Case Else
document.write("My favorite fruit is not available!")
End Select
</script>

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






Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.