View Single Post
 
Old 10-28-2016, 11:29 AM
Cerian Knight's Avatar
Cerian Knight Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,191
Default

You could just change 'Time' to 'Now', but then the date would be spoken first, which might be acceptable to you.

However, I wanted to demonstrate slightly cleaner code (and correct the date/time order in the process):
Code:
Dim sapi,wish,name
name = "Brian"
Set sapi = CreateObject("sapi.spvoice")
If Hour(Now) < 12 Then
 wish = name & ",Good Morning. "
ElseIf Hour(Now)<17 Then
 wish= name & ",Good Afternoon. " 
Else
 wish = name & ",Good Evening. "
End If 
sapi.Speak wish & name & ", the time is " & Time & " " & Date
Notice, among other things, that I changed the concatenation character from '+' to '&', which eliminates the need for 'cstr' to do the explicit type conversion. However, many programmers would use both the '&' and 'cstr' to document that we are working only with string data and that the date/time are not intrinsically strings.

I'm moving this VBScript related topic to 'Miscellaneous Languages', since it is not really VB6.
__________________
I got all the answers wrong on the GLAT, apparently even #9 (where I put a period in the middle of the box and labeled it 'singularity ripe for rapid inflation').

Last edited by Cerian Knight; 10-28-2016 at 11:49 AM.
Reply With Quote