VB语言if一定要有end if结尾吗

VB语言if一定要有end if结尾吗

不是一定.例如
Private Sub Command1_Click()
a = 5

If a > 0 Then MsgBox "hello" '关键是看这里then后面语句,如果仅有一句,不转行.不用endif
if a>0 then '这种情形就一定要!!!
msgbox "yes"
else
msgbox "no"
endif

End Sub

这样就不用.
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-26
不一定,这个分两种形式.
一、if ..... then ... ,这种不用.
二、if ..... then ....
else
....
END IF
这个要.本回答被提问者采纳
第2个回答  2011-01-18
then 后面语句写于if同一行 则不需要end if
多语句写同行可用冒号连接
第3个回答  2011-01-18
不要
相似回答