昨天介绍了request与response的使用,本文将介绍vbscript里的条件语句。

条件语句
演示地址: http://blog.ywask.com/democode/20081111 源码下载:http://blog.ywask.com/democode/20081111.rar

1,if...then...else...end if语句
If...Then...Else 语句用于计算条件是否为 TrueFalse,并且根据计算结果指定要运行的语句。

(1),条件为True时运行语句,分为运行单语句与运行多语句
运行单语句,例:
a=1 '定义变量a的值为1
If a=1 then response.write("yes")  '当a=1时,写出"yes"
上面这样写,因为是单行,省略了end if。
运行多行语句,例:
a=1 '定义变量a的值为1
If a=1 then
        response.write("yes<br>")
        response.write("abcd")
end if
(2),条件为true与false时分别运行语句
例:
a=10 '定义变量a的值为1
if a>100 then
        response.write("大于100")
elseif a>50 then
        response.write("大于50")
elseif a>10 then
        response.write("大于10")
else
        response.write("小等于10")
end if
运行结果为“小等于10”

2,select case 语句
Select Case 结构提供了 If...Then...ElseIf 结构的一个变通形式,可以从多个语句块中选择执行其中的一个。Select Case 语句提供的功能与 If...Then...Else 语句类似,但是可以使代码更加简练易读。
例:
a=10 '定义变量a的值为1
select case a
        case 100
        response.write("等于100")
        case 50
        response.write("等于50")
        case 10
        response.write("等于10")
end select
运行结果为“等于10”