KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

Using select case instead of if-then-else

When choosing between many items it is more efficient to use the select case construct. The following example repeats the registration form but uses Select Case instead of if-then-else for it's decision making.

SelectOneForm.asp
<html>
<head>
<title> Baseball field</title>
</head>
<body>
<h1>BaseBall Information</h1>
<h3>To get the logistics information for your game please answer two questions:</h3>
<form action="SelectAction.asp" method="post">
Please choose your preference in month, either March or April:<br>
<input type="text" Name="monthpref"><p>
Please input your preference in location, either East or West<br>
<input type="text" name="location">
<br>
<input type="submit"><input type="reset">
</form>
</body></html>

SelectAction.asp
<html>
<head>
<title> Baseball field schedule</title>
</head>
<body>
<%
varMonthPref=Request.form("MonthPref")
varLocation=Request.Form("location")

Response.write "<h1> Base ball game </h1>"

select case varMonthPref

case "march"
Response.write "Your meeting will be held on march 15th"
case "March"
Response.write "Your meeting will be held on march 15th"
Case "april"
Response.write "Your meeting will be held on april 16th"
case "April"
Response.write "Your meeting will be held on april 16th"

end select

if varLocation="East" then
response.write "in White Hall, New Mexico"
else
response.write "In Pullman, Idaho"
end if
%>

</body>
</html>

How it works:
The month preferred is saved in variable varMonthPref. Processing is as following in the Select Case statement:

1. The contents of varMonthPref is first compared with "march", if they are equal then the next statement is executed which prints out: Your meeting will be held on march 15th. Execution then continues with the if statement following the End Select

2. Otherwise the contents of varMonthPref is compared with "March" and similar processing is performed as above

3. If varMonthPref is not equal to any of the cases, then nothing is printed and execution continues after the end case.


ASP tutorial
What is ASP
Install IIS
VBScript or JScript
ClientSide vs ServerSide scripting
ASP execution order
Dealing with Form
More Form example
Variable &Variant
String
Local variable
Global variable
Arrays
Use if_then_else
Use Select Case
For_Next loop
Do_while loop
Subroutine vs Function
Request Object
QueryString
Count Keyword
Using QueryString
Application, Method, Events
Create Virtual Directory
Save array in Application
Session, Method, Events
Using Cookie
Server Object
Ad Rotator
Content Linker
Browser
Dictionary object
Filesystemobject Object

 

 

 

Best books about ASP & ASP.Net from Amazon
Beginning Dynamic Websites : with ASP.NET Web Matrix (Programmer to Programmer) (Paperback) Build Your Own ASP.NET Website Using C# & VB.NET (Build Your Own) (Paperback) Professional Active Server Pages 3.0 (Programmer to Programmer) (Paperback) ASP.NET Cookbook (Paperback) ASP.NET Kick Start (Paperback)

 

Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © kidslovepc.com All rights reserved(new). Privacy|Copyright
designed by info@kidslovepc.com

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer