VBScript Tutorials - Herong's Tutorial Examples - v6.02, by Herong Yang
"Select Case" Statement Examples
This section provides a tutorial example on how to use 'Select Case' statements to select one block of statements based on the equal condition of an expected value.
To help you understand how "Select Case" statements work, I wrote the following the example, condition_case.html:
<html> <body> <!-- condition_case.html - Copyright (c) 1998 HerongYang.com. All Rights Reserved. --> <pre> <script language="vbscript"> iDay = 4 Select Case iDay Case 0 sDay = "Sunday" sOpenHours = "closed" Case 1, 2, 3, 4, 5 sDay = "a weekday" sOpenHours = "open from 9:00am to 9:00pm" Case 6 sDay = "Saturday" sOpenHours = "open from 9:00am to 5:00pm" Case Else sDay = "unknown" sOpenHours = "undefined" End Select document.writeln("") document.writeln("Today is " & sDay) document.writeln("The library is " & sOpenHours) </script> </pre> </body> </html>
Here is the output:
Today is a weekday The library is open from 9:00am to 9:00pm
Hope you know how to use "Select Case" statements now.
Table of Contents
Introduction of VBScript - Visual Basic Scripting Edition
Variant Data Type, Subtypes, and Literals
Numeric Comparison Operations and Logical Operations
String Operations - Concatenation and Comparison
Variable Declaration and Assignment Statement
Expression and Order of Operation Precedence
Statement Syntax and Statement Types
Array Data Type and Related Statements
Array References and Array Assignment Statements
►Conditional Statements - "If ... Then" and "Select Case"
►"Select Case" Statement Examples
Loop Statements - "For", "While", and "Do"
"Function" and "Sub" Procedures
Inspecting Variables Received in Procedures
Error Handling Flag and the "Err" Object
Regular Expression Pattern Match and Replacement
scrrun.dll - Scripting Runtime DLL Library
IE Web Browser Supporting VBScript