HERE's A FAR SIMPLER ALTERNATIVE: in just 70lines,

valid inputs are: "x=4+12 OUTPUT: 'x=16' " OR "4+12 OUTPUT: '16' "

Just select the expression you want to calculate & press Ctrl+Shift+C,the answer as in the examples will replace selected expression. CHEERS.

Code: Select all

```
#SingleInstance, force
#NoTrayIcon
/*
Copy selected input which must be an expression,then execute it as a separate script that pastes the value of the expression inplace of the selected input:
Examples: ;select the string to evaluate as an expression
x=4+12 OUTPUT: 'x=16'
OR
4+12 OUTPUT: '16'
*/
^+c:: ;calculate select text as an expression
GetExecExpression()
Return
GetExecExpression(){
Send ^c
; MsgBox, DEBUG1 = %clipboard%
if clipboard contains `= ;if expression is sth like x=123+4524, then the value of x is output as 'x'='value'
{
Loop, Parse, clipboard, `= ;split the equation
{
if (A_Index=1)
varOutName:=A_LoopField
else
expression.=A_LoopField
}
execExp=
(
%varOutName%:=%expression%
%varOutName%:=Round(%varOutName%, 3)
Clipboard:=%varOutName%
)
ExecScript(execExp, true)
clipBuffer:=Clipboard
Clipboard:= varOutName . "=" . clipBuffer
; MsgBox, DEBUG2 = %clipboard%
if clipBuffer is number
Send ^v ;once expression is calculated & a valid number in the clipboard paste output value
else
MsgBox, 0x40010, %A_ScriptName%, Selected Input was not an expression!
}
else ;if expression is sth like 2(123+123)/4, then the value of the expression is output as 'value'
{
execExp=
(
x:=%clipboard%
x:=Round(x, 3)
Clipboard:=x
)
ExecScript(execExp, true)
clipBuffer:=Clipboard
; MsgBox, DEBUG3 = %clipboard%
if clipBuffer is number
Send ^v ;once expression is calculated & a valid number in the clipboard paste output value
else
MsgBox, 0x40010, %A_ScriptName%, Selected Input was not an expression!
}
}
; ExecScript: Executes the given code as a new AutoHotkey process.
ExecScript(Script, Wait:=true)
{
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
exec.StdIn.Write(script)
exec.StdIn.Close()
if Wait
return exec.StdOut.ReadAll()
}
```

Outsourcing Clicks & Presses Since 2004.