ASP Getting Started Tutorial: ASP Select case
In the last lesson you learned how to set a block if the state uses ElseIf keywords, but this is not the most effective way to check multiple conditions. ASP technology use of the choice as an example, check more, equal to the "=" condition of a variable.
If you are an experienced programmer, you will realize that the SELECT statement is similar to the declaration of a switch and that other programming languages use an efficient way to check a large number of conditions at once.
Selected ASP Instance
The occurrence of the variable immediately after the selection of cases is to be examined in the case of a list of speakers. These case reports contain code blocks that are in the selection case. The following is an ASP selection case, which only checks the integer value. Later, we will show how to check the string.
<%
Dim MyNum
MyNum = 5
Select Case MyNum
Case 2
Response.Write ("MyNum is Two")
Case 3
Response.Write ("MyNum is Three")
Case 5
Response.Write ("MyNum is Five")
Case Else
Response.Write ("MyNum is" & MyNum)
End Select
%>
Show Results:
MyNum is five
ASP Select case-case Else
In the past, for example, you may have found some strange, and there is a case that is called "Jurisprudence thing." "This case is actually a catch all the choice of every case that does not conform to the prescribed case." In English this may be thought to be: if all these situations do not match, I will use "Case stuff!" ”
It is a good programming practice to always include all other cases of catch catches. Below, we have an example that always executes the other cases
<%
Dim MyNum
MyNum = 454
Select Case MyNum
Case 2
Response.Write ("MyNum is Two")
Case 3
Response.Write ("MyNum is Three")
Case 5
Response.Write ("MyNum is Five")
Case Else
Response.Write ("MyNum is" & MyNum)
End Select
%>
When the Select case is a string variable
So far we've only used integers to select Case reports, but you can also use string variables for declarations. Below we select a string of
<%
Dim Mypet
Mypet = "Cat"
Select Case Mypet
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
%>
Show Results:
I do not own a cat