ASP Getting Started Tutorial: ASP Select case

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.