VBif结构

来源:百度知道 编辑:UC知道 时间:2024/06/18 10:33:20
一个显示系统时间的IF结构.
请帮我提出错误
if h<12 then
print"早上好"
if h<18 then
print"下午好"
end if
else
print"晚上好"

end if

为什么时间为9点,却显示早上好,下午好.我本意是要显示早上好的.还有这种结构有错吗?
刚学的VB,好烦啊.

正确的格式为:If 条件语句

Then 执行语句
Elseif 条件语句
Then 执行语句
Elseif ..........
..................

End If

Private Sub Command1_Click()
dim h as integer
h = InputBox("输入时间")
k = IIf(h > 12, IIf(h < 18, "下午好", "晚上好"), "早上好")
Print k
End Sub

if h<12 then
print"早上好"
elseif h<18 then
print"下午好"
else
print"晚上好"
end if

if h > 0 and h < 12 then
print"早上好"
elseif h > 12 and h < 18 then
print"下午好"
else
print"晚上好"
end if