Search code examples
vb6

How can i send time after time 12am vb6


I have coded it, but it doesn't do what i have coded. Here is my code looks like:

Private Sub timer_Timer()
    dateoutput.Caption = Format(Now, "General date")
        If theTime >= #12:00:00 AM# And theTime <= #11:59:59 AM# Then
            welcome.Caption = "Good Morning"
        ElseIf theTime >= #11:59:59 AM# And theTime <= #6:00:00 PM# Then
            welcome.Caption = "Good Evening"
        ElseIf theTime >= #6:00:00 PM# And theTime <= #11:59:59 PM# Then
            welcome.Caption = "Good Night"
        End If
End Sub

Solution

  • I think the problem is that you are comparing something that has a date component to something that doesn't, so you'll never get it to work the way you want.

    This is better:

    Private Sub Timer_Timer()
        Dim theTime As String
        theTime = TimeValue(Now)
    
        dateOutput.Caption = Format(Now, "General date")
    
        If theTime >= #12:00:00 AM# And theTime < #12:00:00 PM# Then
            welcome.Caption = "Good Morning"
        ElseIf theTime >= #12:00:00 PM# And theTime < #6:00:00 PM# Then
            welcome.Caption = "Good Evening"
        ElseIf theTime >= #6:00:00 PM# And theTime <= #11:59:59 PM# Then
            welcome.Caption = "Good Night"
        End If
    End Sub
    

    Also note I've changed the values used for the check ranges slightly. Edit It doesn't like checking "< #12:00:00 AM#" so it needs to be "< #11:59:59 PM#"