|
-
Mar 22nd, 2006, 08:25 AM
#1
Thread Starter
Junior Member
[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.
-
Mar 22nd, 2006, 08:42 AM
#2
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
-
Mar 22nd, 2006, 08:50 AM
#3
Thread Starter
Junior Member
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".
-
Mar 22nd, 2006, 08:53 AM
#4
Re: "Good Morning/Afternoon"
 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. 
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.
-
Mar 22nd, 2006, 08:59 AM
#5
Thread Starter
Junior Member
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?
-
Mar 22nd, 2006, 09:04 AM
#6
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
-
May 18th, 2006, 04:17 AM
#7
Lively Member
Re: [RESOLVED] "Good Morning/Afternoon"
Does this code work on PPC ?
I tried it but it doesn't seem to work.
-
May 18th, 2006, 04:46 AM
#8
Re: "Good Morning/Afternoon"
 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
-
May 18th, 2006, 04:46 AM
#9
Re: [RESOLVED] "Good Morning/Afternoon"
 Originally Posted by Winder
Does this code work on PPC ?
I tried it but it doesn't seem to work.
What is PPC??????
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|