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語句