|
|
In the previous lesson you learned how to setup a block of If Statements using the ElseIf keyword,but for checking multiple conditions this is not the most efficient method .
To check for multiple Is Equal To "=" conditions of a single variable,ASP uses the Select Case statement.
If you are an experienced programmer you realize the Select statement resembles a Switch statement that other programming languages use for an efficient way to check a large number of conditions at one time
|
|
ASP Select Case Example
|
|
The list of case statements is checked against the variable that appears immediately after Select Case
Within the Select Case block of code,these case statements are contained
Below is an ASP Select Case example which checks for integer values.
Later we will show how to check for strings
|
|
ASP Code:
|
<%
Dim CaseNum
myNum = 5
Select Case CaseNum
Case 2
Response.Write("CaseNum is Two")
Case 3
Response.Write("CaseNum is Three")
Case 5
Response.Write("CaseNum is Five")
Case Else
Response.Write("CaseNum is " & myNum)
End Select
%>
|
|
|
|
|
ASP Select Case - Case Else
|
|
In the last example you might have noticed something strange, there was a case that was referred to as "Case Else".
This case is actually a catch all option for every case that does not fit into the defined cases.
In english it might be thought of as: I'll use the "Case Else"! if all these cases don't match
-
It is a good programming practice to always include the catch all Else case. Below we have an example that always executes the Else case
|
|
ASP Code:
|
<%
Dim CaseNum
CaseNum = 454
Select Case CaseNum
Case 2
Response.Write("CaseNum is Two")
Case 3
Response.Write("CaseNum is Three")
Case 5
Response.Write("CaseNum is Five")
Case Else
Response.Write("CaseNum is " & myNum)
End Select
%>
|
|
|
|
|
Select Case with String Variables
|
|
So far we have only used integers in our Select Case statements, but you can also use a string as the variable to be used in the statement.
Below we Select against a string
|
|
ASP Code:
|
<%
Dim CasePet
myPet = "cat"
Select Case CasePet
Case "dog"
Response.Write("I own a dog")
Case "cat"
Response.Write("I do not own a cat")
Case Else
Response.Write("I once had a cute goldfish")
End Select
%>
|
|
|
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
asp if statement response.write, asp if statement string,
asp if statement dim, asp tutorial
|
|
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
| Database Quizes |
|
|
| Operating System Quizes |
|
|
| Software Testing Quizes |
|
|
| SAP Module Quizes |
|
|
| Networking Programming Quizes |
|
|
| Microsoft Office Quizes |
|
|
| Accounting Quizes |
|
|
| Computer Basics Quizes |
|
|
|