VBS 控制语句

1.if...then...end if数组

 

if [条件] thenoop

[执行语句]this

end ifspa

 

能够嵌套 多个ifinput

if [条件] thenit

[执行语句]变量

else if [条件] thenselect

[执行语句]循环

end ifim

 

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

相关文章
相关标签/搜索