Vbscript Select Case in ASP
In ASP Vbscript Select case can be used as an alternate to if then elseif statements when you have to execute one out of many blocks of code. During code execution process each select case condition is matched with evaluated expression for the variable passed to the select case test condition statement.
Classic ASP VbScript Basics Examples:
You can see the live samples and examples of Classic ASP VbScript Basics from the following links:
Syntax for Vbscript Select Case in ASP
Select case variableName Case [test value of variable] 'Code lines to be executed when case condition test returns true. Case [test value of variable] 'Code lines to be executed when case condition test returns true. Case Else 'Code lines to be executed when none of the above case conditions return true. End Select
Example of Vbscript Select Case in ASP
<% Dim grade Select Case grade Case "A" Response.Write "Brilliant" Case "B" Response.Write "Excellent" Case "C" Response.Write "Good" Case "D" Response.Write "Satisfactory" Case Else Response.Write "Fail" End Select %>
Vbscript exits after passing the first available conditional test in the select case statements. If condition returns true in first case then it executes the code below the first case block and exits the select case. If no select case condition returns true then case else code is executed by default.
Continue to next tutorial: Vbscript For Loop in ASP to learn how to execute the same code lines multiple times