asp中不能用switch语句,要用select case语句了
简单的介绍一下
选择报表的工作一样,如果语句。然而不同的是,他们可以检查多个值。当然,你有
多个相同的,如果.. else语句,但是这并不总是最好的方法。
选择语句允许一个程序来计算表达式,并试图匹配表达式的值案件标签。如果找到匹
配,程序执行相关的声明。对于SELECT语句的语法如下:
select case expression case label_1 statements_1 case label_2 statements_2 ... case else statements_n end select
该计划首先查找与匹配的表达式的值标签的情况,然后条控制转移到该条款,执行相
关的声明。如果没有找到匹配的标签,程序查找任择案Else子句,如果发现,将控制
转移到该条款,执行相关的声明。如果没有Case Else子句发现,程序继续执行的声明
后选择结束。利用休息时间,避免因进入下一个代码自动执行。
让我们考虑一个例子:
<%@ 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 our shop") end select %>
例子1、
<% '/*ASP中用select case代替其他语言中的switch case, default用case else*/ dim today today = 5 select case today case 0 str = "星期天" case 1 str = "星期一" case 2 str = "星期二" case 3 str = "星期三" case 4 str = "星期四" case 5 str = "星期五" case 6 str = "星期六" case 7, 8, 9 str = "today的值是7,8,或9" case else str = "未知" end select response.write str response.End() %> /*------------输出结果-------- 星期五 ------------*/
实例2、
board=request("board") select case board case "1" boardName = "技术版" case "2" boardName = "信息版" case "3" boardName = "客服星空" case "4" boardName = "灌水区" case "5" boardName = "市场营销" case "6" boardName = "经理论坛" case "7" boardName = "影音论坛" case "8" boardName = "延伸服务" case "9" boardName = "东北片区" case "10" boardName = "市场动态" case "11" boardName = "群发交流" case "12" boardName = "hombre" case "14" boardName = "论坛" case "15" boardName = "在线答疑" case else boardName = "查字典教程网" end select
注意:case "1"后面不能有冒号,boardName = "技术版"后面不能有分号,而且不能出现break语句