VB高手请进,在先等!!!

来源:百度知道 编辑:UC知道 时间:2024/06/14 18:43:21
在If语句中,有时候可以用Then结束,有时侯有了Then却还必须要以End If结束,这两者有什么区别?怎么判断是不是要加End If?请说仔细些,谢谢!!

分段写必须要end if 写成一行就可不用end if
如:
if a>1 then b=2

if a>1 then
b=2
end if

你看一下语法
1. if 条件 then 语句

2. if 条件 then
语句
end if

也就是说如果语句跟then放在同一行就不需要end if,否则需要end if

要决定某个语句是否为一个 If 块,可检查 Then 关键字之后是什么。如果在 Then 同一行之后,还有其它非注释的内容,则此语句就是单行形式的 If 语句。

Else 和 ElseIf 子句都是可选的。在 If 块中,可以放置任意多个 ElseIf 子句,但是都必须在 Else 子句之前。If 块也可以是嵌套的。

单行的不需要,
比如
if text1.text = "我是" then msgbox "正确"

但如果格式换下
if text1.text = "我是" then
msgbox "正确"
end if
对比下,...
给分哦

其实就是这么简单的一件事.只要你接受就行了.不用多想.
1. if 条件 then 语句

2. if 条件 then
语句
end if
3.if 条件1 then
语句1
else
语句2
end if
4.3.if 条件1 then
语句1
elseif 条件2 then
语句2
elseif 条件3 then
语句3

......

elseif 条件n then
语句n
end if

当 if ... then 后 条件真和/或假只执行一