Friday, 7 February 2014

Speaking Calculator

Create own speaking calculator like ROBOT:

Steps:
1.Open notepad copy & paste the following coding
2.Save like speaking clock.vbs then click

coding:

Dim expr,sapi, mul, div, add,subtr, op1, op2, typ, pow, modu
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

No comments:

Post a Comment