关于VB的一点小疑问?

来源:百度知道 编辑:UC知道 时间:2024/05/21 13:53:04
Private Sub Form_Load()
If Hour(Now) >= 0 And Hour(Now) < 8 Then Label1 = "A"
ElseIf Hour(Now) >= 8 And Hour(Now) < 10 Then Label1 = "B"
Else: Label1 = "C"
End If
End Sub

为何这段代码运行不了?

因为没有分开来写
Private Sub Form_Load()
If Hour(Now) >= 0 And Hour(Now) < 8 Then
Label1 = "A"
ElseIf Hour(Now) >= 8 And Hour(Now) < 10 Then
Label1 = "B"
Else
Label1 = "C"
End If
End Sub

Private Sub Form_Load()
时间的小时数可能即大于等于0又小于8吗?
If Hour(Now) >= 0 And Hour(Now) < 8 Then
Label1 = "A"
时间的小时数可能即大于等于8又小于10吗?
ElseIf Hour(Now) >= 8 And Hour(Now) < 10 Then
Label1 = "B"
Else
Label1 = "C"
End If
End Sub
将AND修改为OR

二楼说的应该是正确的
if有三种结构
1:if 条件 then 需执行命令
2:if 条件 then
需执行命令
end if
1:if 条件 then
需执行命令
elseif 条件 then
需执行命令
……
end if
第一个为单行代码,第二个为多行
单行与多行结合起来用,不一定能执行

哪里报错?
是不是label1.text = "A" ……