Select Case - Exemplo 2

 

Usando IF-THEN pode ser incômodo e propenso a ter erros de programação e lentidão na execução. Uma construção mais eficiente é o SELECT CASE que utiliza uma variável com várias condições.

   <html><head>
   <TITLE>asp_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
10   <INPUT TYPE="Radio" name="Title" VALUE="manager">Management Candidate
11   <INPUT TYPE="Radio" name="Title" VALUE="executive">Executive
12   <INPUT TYPE="Radio" name="Title" VALUE="vice-prez">The Vice President of...
13   <INPUT TYPE="Radio" name="Title" VALUE="CEO">The Boss<p>
14   <INPUT TYPE=submit><p><INPUT TYPE=reset>
15   </form></body></html>

Este é o select case que determinará o que significa cada input do usuário.

   <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"
10    response.write("The washroom is in the hall")
11    case "manager","executive"
12    response.write("Here is your key to the Executive washroom")
13    case "CEO", "vice-prez"
14    response.write("The maid will attend to your private washroom")
15   End Select%>
16   </body></html>

Voltar


Copyright (c) 1998 - Alexandre Barreto