web 2.0

ASP/VBScript Select Case

ASP/VBScript Select Case Executes one of several groups of statements, depending on the value of an expression.

ShotDev Focus:
- Using Asp and Select Case


Select CaseĀ  testexpression
[Case expressionlist-n
[statements-n]] . . .
[Case Else expressionlist-n
End Select

The Select Case statement syntax has these parts:

Part Description
testexpression Any numeric or string expression.
expressionlist-n Required if Case appears. Delimited list of one or more expressions.
statements-n One or more statements executed if testexpression matches any part of expressionlist-n.
elsestatements-n One or more statements executed if testexpression doesn’t match any of the Case clauses.

If testexpression matches any Case expressionlist expression, the statements following that Case clause are executed up to the next Case clause, or for the last clause, up to End Select. Control then passes to the statement following End Select. If testexpression matches an expressionlist expression in more than one Case clause, only the statements following the first match are executed.

The Case Else clause is used to indicate the elsestatements to be executed if no match is found between the testexpression and an expressionlist in any of the other Case selections. Although not required, it is a good idea to have a Case Else statement in your Select Case block to handle unforeseen testexpression values. If no Case expressionlist matches testexpression and there is no Case Else statement, execution continues at the statement following End Select.

Select Case statements can be nested. Each nested Select Case statement must have a matching End Select statement.



<% Option Explicit %>
<title>ShotDev.Com Tutorial</title>
Dim A
A = 3
Select Case A
Case "1"
Response.write("A = 1 <br>")
Case "2"
Response.write("A = 2 <br>")
Case "3"
Response.write("A = 3 <br>")
Case Else
Response.write("A = "&A)
End Select

Create a asp file and save to path root-path/myasp/



ASP/VBScript & Select Case

Download this script.

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.