solve simple math function inside a variable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MonuKashyap
Posts: 112
Joined: 06 Jun 2016, 21:32

solve simple math function inside a variable

16 Jun 2018, 03:00

How to solve simple math function inside a variable
for example
(I tried, but fail :cry: :cry: :cry: )

a=1+1
ans:=a
msgbox % ans

and it shows "1+1"
how can i get the addition (i mean the ans)??
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: solve simple math function inside a variable  Topic is solved

16 Jun 2018, 04:44

a:=1+1
Cheers.

Edit, maybe you mean something like this,

Code: Select all


a=1+1
ans:=a
msgbox % eval(ans)

/*
    Evalúa una expresión en una cadena.
    Observaciones:
        Las constantes deben especificarse en mayúscula.
        Se aceptan numeros muy grandes.
    Referencia:
        https://www.w3schools.com/jsref/jsref_obj_math.asp
    Ejemplo:
        MsgBox Eval("PI") . "`n" . Eval("2>3") . "`n" . Eval("3>2") . "`n" . Eval("abs(-100)*2+50") . "`n" . Eval("143**143")
*/
Eval(Expression)
{
    local
	Expression := RegExReplace(Expression, "\s")
    Expression := StrReplace(Expression, ",", ".")
    Expression := RegExReplace(StrReplace(Expression, "**", "^"), "(\w+(\.*\d+)?)\^(\w+(\.*\d+)?)", "pow($1,$3)")    ; 2**3 -> 2^3 -> pow(2,3)
    ;Expression := StrReplace(Expression, "PI", ACos(-1))
    Expression := RegExReplace(Expression, "=+", "==")    ; = -> ==  |  === -> ==  |  ==== -> ==  |  ..
    Expression := RegExReplace(Expression, "\b(E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2)\b", "Math.$1")
    Expression := RegExReplace(Expression, "\b(abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)\b\(", "Math.$1(")

    o := ComObjCreate("HTMLfile")
    o.write("<body><script>document.body.innerText=eval('" . Expression . "');</script>")
    o := StrReplace(StrReplace(StrReplace(InStr(o:=o.body.innerText, "body") ? "" : o, "false", 0), "true", 1), "undefined", "")
    Return o ;InStr(o, "e") ? Format("{:f}", o) : o
} ; https://autohotkey.com/boards/viewtopic.php?f=6&t=15389

from https://github.com/flipeador/AutoHotkey ... h/Eval.ahk. There are other Eval functions available, search.
MonuKashyap
Posts: 112
Joined: 06 Jun 2016, 21:32

Re: solve simple math function inside a variable

16 Jun 2018, 08:53

its rocking!!! Thank You So Much!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 236 guests