Using Select Case in ASP to replace switch case in other languages, default case Else_ application technique

Source: Internet
Author: User
Tags case statement switch case

You cannot use the switch statement in ASP, you need to use the Select Case statement

A Brief introduction

Select the work of the report, if the statement. The difference, however, is that they can check for multiple values. Of course, you have
Many of the same, if. Else statement, but this is not always the best method.
The SELECT statement allows a program to evaluate the expression and attempt to match the value of the expression to the case label. If you find a horse
With, the program executes the related declaration. The syntax for the SELECT statement is as follows:

Select Case expression Case 
  label_1
   statements_1 case
  label_2
   statements_2
  ...
  Case Else
   statements_n end
Select

The plan first looks for the case with the value tag of the matching expression, and then the control shifts to the clause, performing the phase
Off the statement. If no matching tag is found, the program looks for the optional ELSE clause and, if found, controls
Transfer to the clause and execute the relevant statement. If no case Else clause is found, the declaration that the program continues to execute
End after selection. Use the rest time to avoid automatic execution by entering the next code.
Let's consider an example:

<%@ language= "VBScript" >
<%
Dim Flower
Flower = "Rose"
Select Case Flower case
 "Rose" 
   Response.Write (Flower & "costs $2.50") Case
 "Daisy"
   Response.Write (Flower & "costs $1.25")
 Case ' Orchild ' 
   Response.Write (Flower & "costs $1.50") Case
 Else 
   Response.Write ("There is no such Flower in my shop "] End
Select
%>

Example 1,

<%
'/*asp replaces switch case in other languages with Select Case, default with Case else*/Dim today
= 5
Select Case Today's case
 0 
 str = ' Sunday ' case
 1
 str = ' Monday ' case
 2
 str = ' Tuesday ' case
 3
 str = ' Wednesday ' C29/>case 4
 str = "Thursday" case 
 5
 str = ' Friday ' case
 6
 str = ' Saturday ' case
 7, 8, 9
 str = ' Today The value is 7, 8, or 9 "case
 else
 	str =" Unknown "End
Select

Response.Write str
Response. End ()
%>/

*------------output--------
Friday
------------* *

Instance 2,

Board=request ("board")
 Select Case Board Case   
     "1"
     boardname = "Technical version" case
     "2"
     boardname = "Information Edition" Case    
     "3"
     Boardname = "Customer Service star" Case
     "4"
     boardname = "Irrigation Area" Case
     "5"
     boardname = "Marketing"
     case "6"
     boardname = "Manager Forum" case
     "7"
     boardname = "AV Forum" case
     "8"
     boardname = "Extended service" case
     "9" C19/>boardname = "Northeast Area" Case
     "ten"
     boardname = "Market dynamics" case
     "one"
     boardname = "Mass Exchange" case
     "12" C25/>boardname = "Hombre" Case
     "
     boardname =" forum "case" "
     boardname =" Online answer "case
		 else< C31/>boardname = "Cloud Habitat Community" end
Select

Note: The case "1" can not be followed by a colon, boardname = "Technical version" can not have a semicolon after, and the break statement can not appear

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.