VB:If...End If...格式

来源:百度知道 编辑:UC知道 时间:2024/07/04 09:37:43
Private Sub Cmd1_Click()
If Opt1.Value = True Then Txt1.Text = fun(7)
If Opt2.Value = True Then Txt1.Text = fun(9)
End Sub
这样写就不用写END IF
Private Sub Cmd1_Click()
If Opt1.Value = True Then
Txt1.Text = fun(7)
End If
If Opt2.Value = True Then
Txt1.Text = fun(9)
End If
End Sub
这样分两行就要写END IF,觉得挺有意思的,请明白人讲讲这是为什么
还有。。。我好想记得老师说必须在THEN之后回车,但这个不用回车也能运行 是不是我记错了

这个是语句的格式规范
If XXX then XXX 在一行内完成IF语句,则不需要End If结尾,算是IF的简略写法
而正规的IF语句应该为:
If XXX then
XXX
else
XXX
End If
希望这样解释你能理解~