"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:

<!-- condition_case.html
 - Copyright (c) 1998 HerongYang.com. All Rights Reserved.
<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("Today is " & sDay)
   document.writeln("The library is " & sOpenHours)

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

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 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"

 "If" Statements

 "If" Statement Examples

 "Select Case" Statements

"Select Case" Statement Examples

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)


 Full Version in PDF/EPUB