Select Case是根据一个变量或表达式的值是几个特定值中的一个,来执行一组命令。
示例:
DayNumber = Weekday(Day())
Select Case DayNumber
Case vbMonday: MsgBox "It's Monday!"
Case vbTuesday: MsgBox "It's Tuesday!"
Case vbWednesday: MsgBox "It's Wendnesday!"
Case vbThursday: MsgBox "It's Thursday!"
Case vbFriday: MsgBox "It's Friday!"
Case Else MsgBox "It's Weekend!"
End Select
当Select Case语句运行时,VBScript查看DayNumber的值,并且只运行匹配的那个Case项后面的那些命令,如果没有任何列举出的匹配的值,则执行“Case Else”后面的值;
Select Case和If...Then...的区别:
当判断条件的结果的值为一个范围,不便一一列举,则适合使用If...Then...
当判断条件的结果的值为一个具体的值,而且范围较小,可以一一列举,则适合使用Select Case
转载于:https://blog.51cto.com/281816327/1364664