Speaking time Windows
Speaking time Windows
Speaking time Windows
Speaking time Windows
Speaking time Windows
Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows
Speaking time Windows Speaking time Windows
Speaking time Windows
Go Back  Xtreme Visual Basic Talk > > > Speaking time Windows


Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2016, 06:09 PM
b_rianv b_rianv is offline
Newcomer
 
Join Date: Sep 2014
Posts: 13
Default Speaking time Windows


Good evening,

I am working with this code and I am getting this error,can someone help?

Script speak2.vbs
Line 9
Char 59
Error Unterminated string constant
Code 800A0409
Source Microsoft VBScript compilation error

Here is the code

Code:
Dim sapi,hr,ampm,wish
Set sapi = CreateObject("sapi.spvoice")
if(hour(now)=0)then
ampm="AM"
end if
if(hour(now)=12)then
ampm="PM"
end if
if(hour(now)<12)then ampm="AM end if if(hour(now)?12) then
ampm="PM"
end if
select case hour(now)
case 0: hr="12"
case 1: hr="1"
case 2: hr="2"
case 3: hr="3"
case 4: hr="4"
case 5: hr="5"
case 6: hr="6"
case 7: hr="7"
case 8: hr="8"
case 9: hr="9"
case 10: hr="10"
case 11: hr="11"
case 12: hr="12"
case 13: hr="1"
case 14: hr="2"
case 15: hr="3"
case 16: hr="4"
case 17: hr="5"
case 18: hr="6"
case 19: hr="7"
case 20: hr="8"
case 21: hr="9"
case 22: hr="10"
case 23: hr="11"
end select
if(hour(now)>=0 and  hour(now)<12 then wish="Good Morning Brian" end if if(hour(now)>=12 and hour(now)<=17)
then wish="Good Afternoon Brian" end if if(hour(now)>17 and hour(now)<=23) then wish="Good Evening Brian"
end if 
sapi.Speak wish+". Brian, the time is "+ hr+" "+ampm
Thank you,
Brian
Reply With Quote
  #2  
Old 10-24-2016, 07:23 PM
Cerian Knight's Avatar
Cerian KnightSpeaking time Windows Cerian Knight is offline
Polymath (in disciplina)

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

The source webpage was corrupted. This different, but similarly corrupted copy:
Code:
if(hour(now)<12)then ampm="AM" end if if(hour(now)>12) then
ampm="PM"
end if
... should look something like this (in following with the original's poor structure):
Code:
if(hour(now)<12) then
ampm="AM"
end if
if(hour(now)>12) then
ampm="PM"
end if
__________________
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-24-2016 at 07:28 PM.
Reply With Quote
  #3  
Old 10-26-2016, 05:41 AM
b_rianv b_rianv is offline
Newcomer
 
Join Date: Sep 2014
Posts: 13
Default

Thank you, after I really started to look at it I found a few other errors. It is working now very well.
Reply With Quote
  #4  
Old 10-26-2016, 05:46 AM
b_rianv b_rianv is offline
Newcomer
 
Join Date: Sep 2014
Posts: 13
Default

Here is the working code for me...

Code:
Dim sapi,hr,ampm,wish
Set sapi = CreateObject("sapi.spvoice")
if(hour(now)=0)Then
ampm="AM"
end if
if(hour(now)=12)Then
ampm="PM"
end if
if(hour(now)<12)Then ampm="AM" end if 

if(hour(now)>12)Then ampm="PM" end if

select case hour(now)
case 0: hr="12"
case 1: hr="1"
case 2: hr="2"
case 3: hr="3"
case 4: hr="4"
case 5: hr="5"
case 6: hr="6"
case 7: hr="7"
case 8: hr="8"
case 9: hr="9"
case 10: hr="10"
case 11: hr="11"
case 12: hr="12"
case 13: hr="1"
case 14: hr="2"
case 15: hr="3"
case 16: hr="4"
case 17: hr="5"
case 18: hr="6"
case 19: hr="7"
case 20: hr="8"
case 21: hr="9"
case 22: hr="10"
case 23: hr="11"
end select
if(hour(now)>=0) and (hour(now)<12)Then wish="Brian,Good Morning" end if 
if(hour(now)>=12) and (hour(now)<=17)Then wish="Brian,Good Afternoon" end if
if(hour(now)>=17) and (hour(now)<=23)Then wish="Brian,Good Evening" end if 

sapi.Speak wish+". Brian, the time is "+ hr+" "+ampm
It works very good!!!

Now my other question is this.
How could I get this code to speak every 30 minutes?
Example...
Brian,Good morning
Brian,the time is 7:00 am
then 30 minutes later it would run again
Brian,Good morning
Brian,the time is 7:30 am
So on and so forth.

Thank you for your help
Brian
Reply With Quote
  #5  
Old 10-26-2016, 06:59 AM
passel's Avatar
passelSpeaking time Windows passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,015
Default

<edit> Caveat: Your file "vbs" is suggesting vbscript, and I don't know vbscript, so the below response is probably completely wrong. I wrote it thinking VB6, but then realized, looking back, that is probably wrong.</edit>

I guess I would use a NextTime value and set it to the next time you want the "clock" to speak. Then depending on what resolution you want (how close to the exact minute or second you want), use a timer to periodically check to see if it is time to call your code.
For instance, you could set the Timer Interval to 10000 to "wake up" every 10 seconds, and check the time. If you're equal to, or slightly (within 10 seconds) of your speak time, call your code, and update nextTime to the next half hour.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 10-26-2016 at 07:04 AM.
Reply With Quote
  #6  
Old 10-26-2016, 03:26 PM
Cerian Knight's Avatar
Cerian KnightSpeaking time Windows Cerian Knight is offline
Polymath (in disciplina)

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

Quote:
Originally Posted by b_rianv View Post
How could I get this code to speak every 30 minutes?
The least amount of effort is to change the last line to:
Code:
sapi.Speak wish+". Brian, the time is "+cstr(Time)
... which you might notice makes all the code from 'Select Case' to 'End Select' unnecessary, since the 'hr' variable is no longer used. The seconds will be spoken, as well.

Then use the Windows Task Scheduler to create a daily task that starts the vbs on the hour and recurs every 30 minutes.
__________________
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-26-2016 at 03:42 PM.
Reply With Quote
  #7  
Old 10-27-2016, 04:25 AM
b_rianv b_rianv is offline
Newcomer
 
Join Date: Sep 2014
Posts: 13
Default

Thank you I believe this will work great!
Reply With Quote
  #8  
Old 10-28-2016, 04:50 AM
b_rianv b_rianv is offline
Newcomer
 
Join Date: Sep 2014
Posts: 13
Default Would like to have

This works great Sir! Thank you so much but I would also like this code to also speak current (day of week and date) along with the time. I can't find any code to incorporate in to this script and where I would add it to the script so that it will do this.
Example of what the code would say...
Brian, Good morning!
Brian, the time is, 7:30 a.m. Friday October 28 2016
So on and so forth

Van you or someone help me please??

Here is the working code you helped me with.

Code:
Dim sapi,hr,ampm,wish
Set sapi = CreateObject("sapi.spvoice")
if(hour(now)=0)Then
ampm="AM"
end if
if(hour(now)=12)Then
ampm="PM"
end if
if(hour(now)<12)Then ampm="AM" end if 

if(hour(now)>12)Then ampm="PM" end if

if(hour(now)>=0) and (hour(now)<12)Then wish="Brian,Good Morning" end if 
if(hour(now)>=12) and (hour(now)<=17)Then wish="Brian,Good Afternoon" end if
if(hour(now)>=17) and (hour(now)<=23)Then wish="Brian,Good Evening" end if 

sapi.Speak wish+". Brian, the time is "+cstr(Time)
Thank you,
Brian
Reply With Quote
  #9  
Old 10-28-2016, 11:29 AM
Cerian Knight's Avatar
Cerian KnightSpeaking time Windows Cerian Knight is offline
Polymath (in disciplina)

Super Moderator
* Expert *
 
Join Date: May 2004
Location: Michigan
Posts: 4,177
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
  #10  
Old 10-28-2016, 04:56 PM
b_rianv b_rianv is offline
Newcomer
 
Join Date: Sep 2014
Posts: 13
Default

Thank you for all of your time. It really hepled.
!
Reply With Quote
Reply

Tags
code, error, dim, source, sapi, hr, ampm, wish, vbscript, microsoft, compilation, createobjectsapi.spvoice, ifhournow=12then, ampm=pm, ifhournow, ampm=am, ifhournow=0then, sapi, 800a0409, set, unterminated, error, can, evening, time, windows, speaking, string, char


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Speaking time Windows
Speaking time Windows
Speaking time Windows Speaking time Windows
Speaking time Windows
Speaking time Windows
Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows Speaking time Windows
Speaking time Windows
Speaking time Windows
 
Speaking time Windows
Speaking time Windows
 
-->