What is this ?
This is nothing but a speaking calculator which will never show you the result on the screen, rather it will tell you the result just like a robot. So before doing this first verify your volume is not mute and your speaker is good.
How to do this?
There are two ways to do this. Lets see one by one.
1st way (You can enter only two operand)
Just copy and paste the following code in a notepad and save it in .vbs extension
Dim expr,sapi, mul, div, add,subtr, op1, op2, typ, pow, moduI will suggest you to save it as SpeakingClock1.vbs and double click to open the file.
on error resume next
Err.Clear
set sapi = CreateObject("sapi.spvoice")
expr=InputBox("Write an expression to calculate: "+vbcrlf+vbcrlf+"Note: Please enter only two operands."+vbcrlf+vbcrlf+"Example: 5+7","Speaking Calculator")
mul=split(expr,"*")
div=split(expr,"/")
add=split(expr,"+")
subtr=split(expr,"-")
pow=split(expr,"^")
modu=split(expr,"mod")
if(ubound(mul)=1)then
typ="mul"
op1=mul(0)
op2=mul(1)
else
if(ubound(div)=1)then
typ="div"
op1=div(0)
op2=div(1)
else
if(ubound(add)=1)then
typ="add"
op1=add(0)
op2=add(1)
else
if(ubound(subtr)=1)then
typ="subtr"
op1=subtr(0)
op2=subtr(1)
else
if(ubound(pow)=1)then
typ="pow"
op1=pow(0)
op2=pow(1)
else
if(ubound(modu)=1)then
typ="mod"
op1=modu(0)
op2=modu(1)
end if
end if
end if
end if
end if
end if
if(typ="" or not isnumeric(op1) or not isNumeric(op2))then
msgbox "The expression you entered seems to be invalid",vbokonly,"Invalid Expression"
else
select case typ
case "mul": sapi.Speak replace(expr,"*",": multiplied by ")+": is equal to "+ cStr(Eval(expr))
case "div": sapi.Speak replace(expr,"/",": divided by ")+": is equal to "+ cStr(Eval(expr))
case "add": sapi.Speak replace(expr,"+",": plus ")+": is equal to "+ cStr(Eval(expr))
case "subtr": sapi.Speak replace(expr,"-",": minus ")+": is equal to "+ cStr(Eval(expr))
case "pow": sapi.Speak replace(expr,"^",": powered by ")+": is equal to "+ cStr(Eval(expr))
case "mod": sapi.Speak replace(expr,"mod",": modulo ")+": is equal to "+ cStr(Eval(expr))
end select
end if
if Err.Number <> 0 then
msgbox "Description: "+Err.Description,vbokonly,"Error"
end if
2nd way (You can enter any expression)
Just copy and paste the following code in a notepad and save it in .vbs extension
Dim expr,sapiI will suggest you to save it as SpeakingClock2.vbs and double click to open the file.
on error resume next
Err.Clear
set sapi = CreateObject("sapi.spvoice")
expr=InputBox("Write an expression to calculate: "+vbcrlf+vbcrlf+"Example: (6-3*4)*2+3","Speaking Calculator")
sapi.speak "The answer is: "+ cStr(Eval(expr))
if Err.Number <> 0 then
msgbox "Description: "+Err.Description,vbokonly,"Error"
end if
Note: In both of these calculators you can calculate expressions with 4 operators. The operators are Addition(+), Subtraction(-), Multiplication(*), Division(/), Power(^) and Modulo(mod)