【if...then...end if 的用法】

来源:百度知道 编辑:UC知道 时间:2024/06/04 05:43:05
我学的是VBS,问个问题,请看下面的程序单
(1)

dim a,b
a=12
b=13
if b>a then
msgbox("B大于A")
end if

(2)

dim a,b
a=12
b=13
if b>a then msgbox("B大于A")

这两个程序单中,为什么程序(1)需要用end if结尾,而程序(2)则不需要??

1和2中 if..end if 格式是一样的
只不过2中 是if的一行简化写法.
当没有else 或代码较少时可写成一行:
如:
if x>0 then
msgbox "xx"
end if

if x>0 then msgbox "xx"
它们是一样的.简化写法