文章

vbs条件

在 VBScript 中,我们可以使用四种条件语句: If 语句 - 假如您希望在条件为 true 时执行一系列的代码,可以使用这个语句

1
If i=10 Then msgbox "Hello"

If…Then…Else 语句 - 假如您希望执行两套代码其中之一,可以使用这个语句

1
2
3
4
if i=10 Then
   msgbox "Hello"
   i = i+1
end If

If…Then…ElseIf 语句 - 假如您希望选择多套代码之一来执行,可以使用这个语句

1
2
3
4
5
6
7
8
9
if payment="Cash" then
   msgbox "You are going to pay cash!"
 elseif payment="Visa" then
   msgbox "You are going to pay with visa."
 elseif payment="AmEx" then
   msgbox "You are going to pay with American Express."
 else
   msgbox "Unknown method of payment."
end If

Select Case 语句 - 假如您希望选择多套代码之一来执行,可以使用这个语句 类似于switch语句

1
2
3
4
5
6
7
8
9
10
select case payment
 case "Cash"
   msgbox "You are going to pay cash"
 case "Visa"
   msgbox "You are going to pay with visa"
 case "AmEx"
   msgbox "You are going to pay with American Express"
 case Else
   msgbox "Unknown method of payment"
end select
本文由作者按照 CC BY 4.0 进行授权