• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA Time frame and Speech.Speak

GeraldDLT

Member
Hi Chandoo, why do i always get Invalid code? please help.

Thank you,
Gerald

Code:
Sub greetings()
Dim m, a, e

For m = TimeValue("0:00:01 AM") To TimeValue("11:59:59 AM")
  For a = TimeValue("12:00:00 PM") To TimeValue("5:59:59 PM")
    For e = TimeValue("6:00:00 PM") To TimeValue("12:00:00 PM")
        Next e
            Next a
                Next m
               
If Time = m Then
        Application.Speech.Speak ("Good Morning")
ElseIf Time = a Then
            Application.Speech.Speak ("Good Afternoon")
ElseIf Time = e Then
                Application.Speech.Speak ("Good Evening")
Else
MsgBox "Invalid code"
End If

End Sub
 
Try
Code:
Sub Greetings()
    Select Case Time
        Case TimeValue("0:00:01 AM") To TimeValue("11:59:59 AM")
            Application.Speech.Speak ("Good Morning")
        Case TimeValue("12:00:00 PM") To TimeValue("5:59:59 PM")
            Application.Speech.Speak ("Good Afternoon")
        Case TimeValue("6:00:00 PM") To TimeValue("12:00:00 PM")
            Application.Speech.Speak ("Good Evening")
        Case Else
            MsgBox "Invalid Code", vbExclamation
    End Select
End Sub
 
Hi !​
why do i always get Invalid code?​
Bad logic, no needs to loop, a demonstration :​
Code:
Sub Demo()
    Select Case Time
        Case Is < #12:00:00 PM#:  MsgBox "Good morning !"
        Case Is >= #6:00:00 PM#:  MsgBox "Good evening !"
        Case Else:                MsgBox "Good afternoon !"
    End Select
End Sub
Do you like it ? So thanks to click on bottom right Like !
 
Hi !​

Bad logic, no needs to loop, a demonstration :​
Code:
Sub Demo()
    Select Case Time
        Case Is < #12:00:00 PM#:  MsgBox "Good morning !"
        Case Is >= #6:00:00 PM#:  MsgBox "Good evening !"
        Case Else:                MsgBox "Good afternoon !"
    End Select
End Sub
Do you like it ? So thanks to click on bottom right Like !

Never argue with an idiot, he'll bring you down to his level - then beat you with experience

-Marc L

Hate u mate but your damn GENIUS!
 
Back
Top