‘Simple commandline calculator, but handy to have around (batch math is feeble)
‘(a “front-end” to vbscript “eval”, this can be used by batch to obtain accurate
‘and somewhat sophisticated math operations by sending arugments out to it:
‘for /f “tokens=*” %%a in (‘cscript /nologo %1 %test’) do set result=%%a)
‘To use (example): cscript /nologo calcit.vbs ((172+6)*3) * 2^8/34 mod 4
‘(note modulo is “mod”, not “%”)
‘or another, demonstrating fractions: 12.7 / .22
‘Also supports “interactive” mode, with running total: cscript calcit.vbs
’86 * 76 [enter]
‘+4 [enter]
‘/22 [enter]
‘mod 8 [enter]
‘[enter] (gets the final result and quits). ‘
‘Also note it will do hex-to-dec. conversion and math, like: calcit &h70 + &hC, or &h70 + 12
‘(but the results always rendered in decimal, alas.)
‘Will also concatenate numbers using “&” as operator.
set con=wscript.stdin
set cout=wscript.stdout
set t=wscript.arguments
if t.count=0 then
aa=0
cout.write (“enter the math: “)
do while len(aa)>0
aa=con.readline
bb=eval(bb & aa)
cout.writeline(“cur.ttl: ——–“)
cout.writeline(bb)
loop
else
dim a(99)
for i=0 to t.count-1
aa=aa&” “&t(i)
next
cout.writeline(eval(aa))
end if
Related Posts
Add A Comment