A talking number guessing game.

Here’s a surprisingly simple VBScript that plays a number guessing game. It uses your computer’s voice to tell you whether your guess is too high or too low.

Set objVoice = CreateObject(“SAPI.SpVoice”)

intHighNumber = 100
intLowNumber = 1

Randomize
intNumber = Int((intHighNumber – intLowNumber + 1) * Rnd + intLowNumber)

objVoice.Speak “Guess the number!”

Do Until Cint(StrGuess)=IntNumber

strGuess = InputBox(“Enter your guess.”, _
“Guess the Number”)
if strGuess=”” then
Wscript.Quit
elseif Cint(strGuess) > IntNumber then
objVoice.Speak “Too high.”
elseif Cint(strGuess) < IntNumber then
objVoice.Speak “Too low.”
end if

Loop

objVoice.Speak “You guessed it!”

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s