The Talking Clock
A VBScript demo program written by Joshua Trupin
(c) 1996, Microsoft Corporation


This demo shows the conversion of an existing Visual Basic program to VBScript. To do this, the project needed a new (hidden) ActiveX control to play WAV files, and some minor changes made to string functions. In addition, the problems with distributing components (such as WAV files) had to be solved through ActiveX code download services.
Here's the clock: (Press the button to hear the clock speak.)
Here's the code:
<!-- This is the button control  -->

<OBJECT ID="cmdbtn" WIDTH=96 HEIGHT=32
 CLASSID="CLSID:D7053240-CE69-11CD-A777-00DD01143C57">
    <PARAM NAME="Caption" VALUE="Speak!">
    <PARAM NAME="Size" VALUE="2540;846">
    <PARAM NAME="FontCharSet" VALUE="0">
    <PARAM NAME="FontPitchAndFamily" VALUE="2">
    <PARAM NAME="ParagraphAlign" VALUE="3">
    <PARAM NAME="FontWeight" VALUE="0">
</OBJECT>

<!-- This is the WavCtl control  -->

<OBJECT 
	CLASSID="clsid:5BB5C4E3-D723-11CF-A521-00A024A652FA"
	WIDTH=1
	HEIGHT=1
	hspace=0
	vspace=0
	ID=WavCtl1 
>
</OBJECT>

<!-- This is the IETimer control  -->

<OBJECT
	CLASSID="clsid:59ccb4a0-727d-11cf-ac36-00aa00a47dd2"
	id=Timer1
	align=middle
	width=1
	height=1
>
<PARAM NAME="_ExtentX" VALUE="10">
<PARAM NAME="_ExtentY" VALUE="10">
<param name="TimeOut" value="100">
<param name="Enabled" value="True">
</OBJECT>

<SCRIPT language="VBScript">
<!--


'==================================================================
' A late change in the IETimer control changed the event name from
' "Timer" to "Time" and the property from "Interval" to "TimeOut"

Sub Timer1_Time
   ' This is all you need to create a working clock with VBScript
   cmdbtn.caption = Time
End Sub	

'==================================================================
		
Sub cmdbtn_Click
    ' Whenever the user clicks on the time label, set into
    ' motion the code for saying the time.

    ' This is a lot easier than the original parsing mechanism

    Hrs = Hour(Time)
    Mins = Minute(Time)
    Secs = Second(Time)
    
    If Hrs = 0 Then Hrs = 12

    ' Pronounce the "it's"

    WavCtl1.Play "its.wav"

    ' The Hrs is simple - it is a digit between one and twelve, all of
    ' which exist in separate sound files

    WavCtl1.Play (Hrs + 0) & ".wav"
    
    ' Pronounce the "o'clock" on the hour

    If Mins = 0 Then
        WavCtl1.Play "oc.wav"

    ' Pronounce "oh-mins" if mins is a single digit

    ElseIf Mins < 10 Then
        WavCtl1.Play "oh.wav"
        WavCtl1.Play (Mins + 0) & ".wav"

    ' Pronounce a teen digit in its entirety

    ElseIf Mins < 20 Then
        WavCtl1.Play (Mins + 0) & ".wav"

    ' If the Mins are over 20, pronounce the tens part first, followed
    ' by the ones part. For instance, 34 becomes "thirty" "four"

    ElseIf Mins >= 20 Then
        WavCtl1.Play ((Mins \ 10) * 10) & ".wav"
        WavCtl1.Play (Mins Mod 10) & ".wav"
    End If

    ' Don't pronounce "and zero seconds"

    If Secs = 0 Then Exit Sub

    ' Pronounce your "and" after the minutes

    WavCtl1.Play "and.wav"

    ' You can just pronounce any number below twenty straight from the file,
    ' becase you don't need to preface a single digit with an "oh"

    If Secs < 20 Then
        WavCtl1.Play (Secs + 0) & ".wav"

    ' If there are more than 20 seconds, pronounce it in two chunks, just
    ' like above for the minutes segment

    ElseIf Secs >= 20 Then
        WavCtl1.Play ((Secs \ 10) * 10)  & ".wav"
        WavCtl1.Play (Secs Mod 10) & ".wav"
    End If

    ' Say the closing "second" or "seconds," depending upon the number
    ' of seconds elapsed

    If Secs = 1 Then
        WavCtl1.Play "sec.wav"
    Else
        WavCtl1.Play "secs.wav"
    End If

End Sub
-->
</SCRIPT>