Select Case in Classic ASP

Using IF-THEN can be cumbersome, prone to programmer errors and slower to execute. A more efficient construct is SELECT CASE. It is optimized for testing one variable against many conditions.

<html><head>
<TITLE>case2.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<form action="case2respond.asp" method="get">
Your First Name<INPUT NAME="FirstName" MaxLength=20><p>
Your Last Name<INPUT NAME="LastName" MaxLength=20><p>
Your Title
<INPUT TYPE="Radio" name="Title" VALUE="employee">Entry Level
<INPUT TYPE="Radio" name="Title" VALUE="temp" CHECKED>Temporary Employee
<INPUT TYPE="Radio" name="Title" VALUE="manager">Management Candidate
<INPUT TYPE="Radio" name="Title" VALUE="executive">Executive
<INPUT TYPE="Radio" name="Title" VALUE="vice-prez">The Vice President of...
<INPUT TYPE="Radio" name="Title" VALUE="CEO">The Boss<p>
<INPUT TYPE=submit><p>
</form>
</body></html>

Here is the select case that will determine what the form input means.

<html><head>
<TITLE>case2respond.asp</TITLE>
</head><body bgcolor="#FFFFFF">
<%
fname=request.querystring("Firstname")
lname=request.querystring("Lastname")
title=request.querystring("title")
response.write "Nice to Hire You " & fname & " " & lname & "<p>"
Select Case lcase(Title)
case "employee","temp"
response.write("The washroom is in the hall")
case "manager","executive"
response.write("Here is your key to the Executive washroom")
case "ceo", "vice-prez"
response.write("The maid will attend to your private washroom")
End Select%>
</body></html>
Advertisements