Computer Hope

Software => Computer programming => Topic started by: progmer on May 11, 2010, 09:37:34 PM

Title: vbs script, press cancel to exit?
Post by: progmer on May 11, 2010, 09:37:34 PM
Hi i have a vbs script as shown:
Code: [Select]
Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
do
message=InputBox("Enter the text you want spoken","Speak This")
sapi.Speak message
loop
I want to vbs box to keep on apearing on the screen but only exit when i press the cancel button.
So do anyone know the script?
Title: Re: vbs script, press cancel to exit?
Post by: BC_Programmer on May 11, 2010, 09:53:30 PM
Code: [Select]
Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
do
message=InputBox("Enter the text you want spoken","Speak This")

if message <> "" then sapi.Speak message
loop Until message=""


If you press cancel, Inputbox returns an empty string.
Title: Re: vbs script, press cancel to exit?
Post by: progmer on May 12, 2010, 06:43:17 AM
Code: [Select]
Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
do
message=InputBox("Enter the text you want spoken","Speak This")

if message <> "" then sapi.Speak message
loop Until message=""


If you press cancel, Inputbox returns an empty string.
Maybe you don't understand what i really want here.
"Press cancel to exit, Press ok to speak message."
Title: Re: vbs script, press cancel to exit?
Post by: BC_Programmer on May 12, 2010, 07:15:12 PM
That's exactly what it does. just change the Prompt of the InputBox.
Title: Re: vbs script, press cancel to exit?
Post by: progmer on May 13, 2010, 07:55:04 PM
Ok here is another task:
Code: [Select]
'Blank

x=msgbox("Do really wanted to run this program?",4096+64+4,"Confirm.")

'Blank

Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
do
message=InputBox("Enter the text you want spoken","Speak This")
if message <> "" then sapi.Speak message
loop until message= ""
What script should i add at the 'Blank in order to exit the program when i click no?
And i click yes to run the program?
Title: Re: vbs script, press cancel to exit?
Post by: Sidewinder on May 14, 2010, 12:39:19 PM
Code: [Select]
If msgbox("Do really wanted to run this program?",4096+64+4,"Confirm.") = vbNo Then
WScript.Quit
End If

Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
do
message=InputBox("Enter the text you want spoken","Speak This")
if message <> "" then sapi.Speak message
loop until message= ""

For readability, try using using constant names (vbInformation, vbSystemModal) instead of constant values (64, 4096).

 8)
Title: Re: vbs script, press cancel to exit?
Post by: progmer on May 17, 2010, 09:35:57 PM
Code: [Select]
If msgbox("Do really wanted to run this program?",4096+64+4,"Confirm.") = vbNo Then
WScript.Quit
End If

Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
do
message=InputBox("Enter the text you want spoken","Speak This")
if message <> "" then sapi.Speak message
loop until message= ""

For readability, try using using constant names (vbInformation, vbSystemModal) instead of constant values (64, 4096).

 8)

Well thanks!! It works greate.
Here is my code:
Code: [Select]
Do
Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
If InputBox("Enter the text you want spoken","Speak This") = vbCancel then
wscript.quit
End if
sapi.Speak message
loop
My code is wrong and i hope you can help me with it.
Title: Re: vbs script, press cancel to exit?
Post by: BC_Programmer on May 17, 2010, 09:44:41 PM
Here is my code:
Code: [Select]
Do
Dim message, sapi
Set sapi=CreateObject("sapi.spvoice")
If InputBox("Enter the text you want spoken","Speak This") = vbCancel then
wscript.quit
End if
sapi.Speak message
loop
My code is wrong and i hope you can help me with it.

If you press cancel, Inputbox returns an empty string.
Title: Re: vbs script, press cancel to exit?
Post by: progmer on May 19, 2010, 07:12:01 AM

I hope anyone can help me with this......

press cancel, inputbox returns an empty string.


press the "x" button, the script exit.

This is actually what i want.
Title: Re: vbs script, press cancel to exit?
Post by: BC_Programmer on May 19, 2010, 08:45:23 AM
pressing "X" on the prompt window also causes the Inputbox() function to return an empty string.