Select Case does a similar job to If..Then..Else..
Below is an example using a variable called Name. Depending on whether
Name equals Michael, Gavan, Fred or none of these names a different
line of code is run.
<%
SELECT CASE Name
Case Michael
Response.write Name is Michael
Case Fred
Response.write Name is Fred
Case Gavan
Response.write Name is Gavan
'It is possible that none of the case statements
equal the value of variable Name
'so in this scenario - use Case Else
Case Else
Response.write "The name is something else"
END SELECT
%>
The above example applies to text. The example below applies to a number.
<%
SELECT CASE Number
Case 1
Response.write Number is equal to 1
Case 2
Response.write Number is equal to 2
Case 3
Response.write Number is equal to 3
'It is possible that none of the case statements
equal the value of variable Number
'so in this scenario - use Case Else
Case Else
Response.write "The number is not equal to any of the values
above "
END SELECT
%>
(Read the second part of this tutorial that will introduce posting form variables and provide a slightly more complicated example select case.)
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.
Get your best asp web hosting provider now and save 25%