[RESOLVED] "Good Morning/Afternoon"
I'm making a program for a company, and I would like it to show a message box saying "Good Morning", or "Good Afternoon", depending on AM/PM.
I have a timer and a label working all fine and good with:
VB Code:
Private Sub TimerTime_Timer()
LblClock.Caption = Format$(Time, "HH:MM:SS AMPM")
End Sub
And then I created a message box on form load:
VB Code:
If LblClock.Caption = "**:**:** AM" Then
MsgBox "Good Morning"
Else
MsgBox "Good Evening"
End If
I'm not too good at Visual Basic, so I'm probably making a really stupid and obvious error, but what is wrong with that code? It doesn't show any message box.
Re: "Good Morning/Afternoon"
VB Code:
If DateDiff("s", CDate("12:00:00 PM"), CDate(lblClock.Label)) < 0 Then
'Earlier than 12:00 PM
MsgBox "Good Morning"
Else
MsgBox "Good Afternoon"
End If
Re: "Good Morning/Afternoon"
Where do I put that? If I put it on Form Load, it gives me the error "Method or Data Member not Found".
Re: "Good Morning/Afternoon"
Quote:
Originally Posted by yatesell
Where do I put that? If I put it on Form Load, it gives me the error "Method or Data Member not Found".
Welcome to the forums. :wave:
Put it in Form_Activate
Your form won't be visible until all the code in the Form Load event has executed so any reference to any controls on that form will generate an error.
Re: "Good Morning/Afternoon"
Cheers. Unfortunately, it still comes up with the error, and it highlights the .label bit on CDate(LblClock.Label))
Would I need to put a value in it first (like 0), and then the 0 would over-write it with the time?
Re: "Good Morning/Afternoon"
In Form_Load the Timer event hasn't been fired yet so the Label doesn't have the correct time, or rather it doesn't contain a value that can be converted to a time so that's why you'll get the error. You can use this code in Form_Load instead:
VB Code:
If DateDiff("s", CDate("12:00:00 PM"),[b] Time[/b]) < 0 Then
'Earlier than 12:00 PM
MsgBox "Good Morning"
Else
MsgBox "Good Afternoon"
End If
Re: [RESOLVED] "Good Morning/Afternoon"
Does this code work on PPC ?
I tried it but it doesn't seem to work.
Re: "Good Morning/Afternoon"
Quote:
Originally Posted by Joacim Andersson
VB Code:
If DateDiff("s", CDate("12:00:00 PM"), CDate(lblClock.Label)) < 0 Then
'Earlier than 12:00 PM
MsgBox "Good Morning"
Else
MsgBox "Good Afternoon"
End If
VB Code:
If DateDiff("s", CDate("12:00:00 PM"), CDate(lblClock.[B]caption[/B])) < 0 Then
'Earlier than 12:00 PM
MsgBox "Good Morning"
Else
MsgBox "Good Afternoon"
End If
Re: [RESOLVED] "Good Morning/Afternoon"
Quote:
Originally Posted by Winder
Does this code work on PPC ?
I tried it but it doesn't seem to work.
What is PPC??????