Results 1 to 9 of 9

Thread: [RESOLVED] "Good Morning/Afternoon"

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    16

    Resolved [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:
    1. Private Sub TimerTime_Timer()
    2.     LblClock.Caption = Format$(Time, "HH:MM:SS AMPM")
    3. End Sub

    And then I created a message box on form load:

    VB Code:
    1. If LblClock.Caption = "**:**:** AM" Then
    2.    MsgBox "Good Morning"
    3.      Else
    4.    MsgBox "Good Evening"
    5. 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.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: "Good Morning/Afternoon"

    VB Code:
    1. If DateDiff("s", CDate("12:00:00 PM"), CDate(lblClock.Label)) < 0 Then
    2.     'Earlier than 12:00 PM
    3.     MsgBox "Good Morning"
    4. Else
    5.     MsgBox "Good Afternoon"
    6. End If

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    16

    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".

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

    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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    16

    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?

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. If DateDiff("s", CDate("12:00:00 PM"),[b] Time[/b]) < 0 Then
    2.     'Earlier than 12:00 PM
    3.     MsgBox "Good Morning"
    4. Else
    5.     MsgBox "Good Afternoon"
    6. End If

  7. #7
    Lively Member
    Join Date
    Apr 2006
    Posts
    108

    Re: [RESOLVED] "Good Morning/Afternoon"

    Does this code work on PPC ?
    I tried it but it doesn't seem to work.

  8. #8
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    Re: "Good Morning/Afternoon"

    Quote Originally Posted by Joacim Andersson
    VB Code:
    1. If DateDiff("s", CDate("12:00:00 PM"), CDate(lblClock.Label)) < 0 Then
    2.     'Earlier than 12:00 PM
    3.     MsgBox "Good Morning"
    4. Else
    5.     MsgBox "Good Afternoon"
    6. End If
    VB Code:
    1. If DateDiff("s", CDate("12:00:00 PM"), CDate(lblClock.[B]caption[/B])) < 0 Then
    2.     'Earlier than 12:00 PM
    3.     MsgBox "Good Morning"
    4. Else
    5.     MsgBox "Good Afternoon"
    6. End If
    CS

  9. #9
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    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??????
    CS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width