VBS 控制语句

1.if...then...end if

if [条件] then

[执行语句]

end if

可以嵌套 多个if

if [条件] then

[执行语句]

else if [条件] then

[执行语句]

end if

eg.

Dim a,b

a=inputbox("please input a")

b=inputbox("please input b")

if a>b

then

msgbox("a>b")

else if a<b

then

msgbox("a<b")

end if

2.select case 变量名

            case 变量值

                    [执行语句]

            case 变量值

                    [执行语句]

select  case var

          case 1

          msgbox "this is room a"

          case 2

          msgbox "this is room b"

3. do while

1) do while 条件

         [执行语句]

    loop

当想要中途退出循环时,可以使用exit

2)do

   [执行语句]

   loop while 条件

先执行语句块,后面判断条件

4. while 条件

            [执行语句]

    wend

5. do while 条件

                 [执行语句]

    loop

    until 条件

6.for i=0 to ubound(Array)

       [执行语句]

    next

ubound表示数组的最大下标,数组下标从0开始,想要中途退出循环可以使用exit for

7. for each x in array

        [执行语句]

    next

想要中途退出循环可以使用exit for

原文地址:https://www.cnblogs.com/wuqm/p/6724224.html