如何在VB中根据时间显示问候语?如:8:00-10:00显示早上好,11:00-12:00显示中午好,以此类推,谢谢。
3个回答
展开全部
Private Sub Timer1_Timer()
Me.Caption = GetGreetings(Now)
End Sub
Function GetGreetings(t As Date) As String
Select Case Hour(Now)
Case 8 To 10: GetGreetings = "早上好"
Case 11 To 12: GetGreetings = "中午好"
' Case 1 To 2'自己添加
Case Else
GetGreetings = "好"
End Select
End Function
追问
我想让那些问候语显示在一个Lebel中,请问如何做呢
追答
Lebel.Caption=GetGreetings(now)
'如果是全部代码 添加一个 timer 控件 interval 属性 设置一个值 你的是以小时算的 大点会节省电脑计算资源 可能会有点不及时 ....自定吧
然后 再 timer事件内加上上面的代码 就行了
上面有点小错
Option Explicit
Private Sub Timer1_Timer()
Label1.Caption = GetGreetings(Now)
End Sub
Function GetGreetings(t As Date) As String
Select Case Hour(t)
Case 8 To 10: GetGreetings = "早上好"
Case 11 To 12: GetGreetings = "中午好"
' Case 1 To 2:GetGreetings = "中午好"'自己添加
Case Else
GetGreetings = "好"
End Select
End Function
展开全部
加一个时钟控件,代码:
Private Sub Timer1_Timer()
h = Hour(Now)
If h = 8 Or h = 9 Then
Me.Caption = "早上好"
ElseIf h = 11 Or h = 12 Then
Me.Caption = "中午好"
ElseIf h >= 18 And h <= 23 Then
Me.Caption = "晚上好"
End If
End Sub
更多追问追答
追问
我想让那些问候语显示在一个Lebel中,请问如何做呢
追答
Me.Caption改成Label1.Caption
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Greet()
If (Hour(Now) >= 5 And Minute(Now) >= 1) And (Hour(Now) <= 6 And Minute(Now) <= 59) Then
Label1.Caption="清晨好"
ElseIf (Hour(Now) >= 7 And Minute(Now) >= 0) And (Hour(Now) <= 8 And Minute(Now) <= 59) Then
Label1.Caption="早上好"
ElseIf (Hour(Now) >= 9 And Minute(Now) >= 0) And (Hour(Now) <= 12 And Minute(Now) <= 0) Then
Label1.Caption="上午好"
ElseIf (Hour(Now) >= 12 And Minute(Now) >= 1) And (Hour(Now) <= 13 And Minute(Now) <= 59) Then
Label1.Caption="中午好"
ElseIf (Hour(Now) >= 14 And Minute(Now) >= 0) And (Hour(Now) <= 17 And Minute(Now) <= 59) Then
Label1.Caption="下午好"
ElseIf (Hour(Now) >= 18 And Minute(Now) >= 0) And (Hour(Now) <= 18 And Minute(Now) <= 59) Then
Label1.Caption="傍晚好"
ElseIf (Hour(Now) >= 19 And Minute(Now) >= 0) And (Hour(Now) <= 23 And Minute(Now) <= 59) Then
Label1.Caption="晚上好"
ElseIf (Hour(Now) >= 24 And Minute(Now) >= 0) And (Hour(Now) <= 5 And Minute(Now) <= 0) Then
Label1.Caption="凌晨好"
End If
End Sub复制去Google翻译翻译结果
If (Hour(Now) >= 5 And Minute(Now) >= 1) And (Hour(Now) <= 6 And Minute(Now) <= 59) Then
Label1.Caption="清晨好"
ElseIf (Hour(Now) >= 7 And Minute(Now) >= 0) And (Hour(Now) <= 8 And Minute(Now) <= 59) Then
Label1.Caption="早上好"
ElseIf (Hour(Now) >= 9 And Minute(Now) >= 0) And (Hour(Now) <= 12 And Minute(Now) <= 0) Then
Label1.Caption="上午好"
ElseIf (Hour(Now) >= 12 And Minute(Now) >= 1) And (Hour(Now) <= 13 And Minute(Now) <= 59) Then
Label1.Caption="中午好"
ElseIf (Hour(Now) >= 14 And Minute(Now) >= 0) And (Hour(Now) <= 17 And Minute(Now) <= 59) Then
Label1.Caption="下午好"
ElseIf (Hour(Now) >= 18 And Minute(Now) >= 0) And (Hour(Now) <= 18 And Minute(Now) <= 59) Then
Label1.Caption="傍晚好"
ElseIf (Hour(Now) >= 19 And Minute(Now) >= 0) And (Hour(Now) <= 23 And Minute(Now) <= 59) Then
Label1.Caption="晚上好"
ElseIf (Hour(Now) >= 24 And Minute(Now) >= 0) And (Hour(Now) <= 5 And Minute(Now) <= 0) Then
Label1.Caption="凌晨好"
End If
End Sub复制去Google翻译翻译结果
追问
我想让那些问候语显示在一个Lebel中,请问如何做呢
追答
已经帮你写好了,直接在时钟控件里面用就是了
Private Sub Timer1_Timer()
Call Greet()
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询