vb if语句中then换行

来源:百度知道 编辑:UC知道 时间:2024/06/15 02:42:11
then 后面的语句换行和不换行有什么区别呢?为什么有的不换行就错了呢,谢谢

if ..then语句的语法结构分为单行,多行

单行的就是这样: if..条件.....then...语句.....

多行的是:
if ...条件.... then
....语句...
else
....语句....

end if

这是语法结构,需要死记的东西!!

if x then xxx

if x then
xxx
endif

这两种都可以.根据你的需要.
如果需要在then 后有多行语句那就
用第二种.

dim a,b as integer
if a-b>0 then a>b '此时就不要end if
'--------------------
dim a,b as integer
if a-b>0 then
a>b
end '此时就要end if
'----------------------
dim a,b as integer
if a-b>0 then
a>b
elseif a-b<0 then
a<b
end if'此时就要一个end if

请注意:两种用法可以互换,都可以用作多行语句处理
用法1:(这种用法就是一句话写到底的做法...)
if <条件> then <语句1>: <语句2>: <语句3> : ... : <语句n> else <语句1>: <语句2>: <语句3> : ... : <语句n>

用法2:
if <条件> then
<语句1>
<语句2>
<语句3>
...
<语句n>