Search Search

#1 worldwide
FREE Coding Lessons

since 1996
   THE BEST WAY to learn ASP & Asp.net!
Advertise Here!
click for details
Credits Host:
DiscountASP.net
Server Admin:
The "Team"
Contact Info.
Charles M. Carroll

my Blog
[prev. Lesson]  Forms: CASE syntax #1
     [next Lesson]  Forms: IF syntax #1

Select Case Part2 (by John Kauffman & Charles Carroll)

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.

   filename=/learn/test/case2.asp

<Test Script Below>


<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.

   filename=/learn/test/case2respond.asp

<Test Script Below>


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

Send Us a Holiday Gift!. Charles celebrates Christmas, Jewish holidays, Kwanza, Chinese New Year, Japanese Holidays, Secretary Day, High Muslim Holy Days, Pagan & Wicca holidays, and many more! - send a gift any HOLIDAY. 2004 gift gallery & 2005 gift gallery