This article mainly introduces the use of select case in ASP to replace the switch case in other languages, and the default case else. Friends who need it can refer to it.
You cannot use switch statements in asp. You must use select case statements.
Briefly introduce
Selecting reports works the same as if statements. However, the difference is that they can check multiple values. Of course you have
Multiple identical if..else statements, but this is not always the best approach.
The select statement allows a program to evaluate an expression and attempt to match the value of the expression to the case label. If you find a match
Configuration, program execution related statements. 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_nend select
The program first looks for a condition with a value label that matches the expression, then the clause control transfers to that clause, executing the corresponding
related statement. If no matching tag is found, the program looks for the optional Else clause and, if found, controls
Move to this clause and execute the relevant statement. If no Case Else clause is found, program execution continues with the statement
Then select End. Take advantage of breaks to avoid automating execution by moving onto the next piece of code.
Let's consider an example:
<%@ language=vbscript><%Dim FlowerFlower = roseselect 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 our shop)end select%>
Example 1.
<%'/*In ASP, use select case instead of switch case in other languages, default use case else*/dim todaytoday = 5select case today case 0 str = Sunday case 1 str = Monday case 2 str = Tuesday case 3 str = Wednesday case 4 str = Thursday case 5 str = Friday case 6 str = Saturday case 7, 8, 9 str = today's value is 7, 8, or 9 case else str = unknown end selectresponse.write strresponse.End()%>/*------------Output results--------Friday------------*/
Example 2.
board=request(board) select case board case 1 boardName = technical version case 2 boardName = information version case 3 boardName = customer service starry sky case 4 boardName = irrigation area case 5 boardName = marketing case 6 boardName = manager forum case 7 boardName = audio and video Forum case 8 boardName = Extended services case 9 boardName = Northeast area case 10 boardName = Market dynamics case 11 boardName = Group communication case 12 boardName = hombre case 14 boardName = Forum case 15 boardName = Online Q&A case elseboardName = Script Home end select
Note: There cannot be a colon after case 1, there cannot be a semicolon after boardName = technical version, and there cannot be a break statement.