hello i'm new at ahkforum , i readed the guide but i didn't found a way to display the result of a multiplication i learn a way to display and insert variable but i don't know how to make an expression and display it in the gui console
her's the code i use
Gui, Add, Text,, first number:
Gui, Add, edit, number vpve
Gui, Add, Text,, second number:
Gui, Add, edit, number vnpe
Gui, Add, Button, Default , result
Gui, Add, edit, result vres
Easy calculator Topic is solved
Re: Easy calculator
You need to create a label for the result button and "Submit" - https://autohotkey.com/docs/commands/Gui.htm#Submit - to get the variables from the Gui. After that you can use GuiControl to update the result edit control.
Code: Select all
Gui, Add, Text,, first number:
Gui, Add, edit, number vpve
Gui, Add, Text,, second number:
Gui, Add, edit, number vnpe
Gui, Add, Button, Default , result
Gui, Add, edit, result vres
Gui, Show
Return
ButtonResult:
Gui, Submit, NoHide
res:=pve*npe
GuiControl,, res, %res%
Return
esc::ExitApp
- silvex3000
- Posts: 188
- Joined: 19 Dec 2015, 22:42
Re: Easy calculator
Wow!
I wrote this code right now, and I don't even believe that Autohotkey can't handle this:
I'm in Shock (very disappointed with AutoHotkey)
I wrote this code right now, and I don't even believe that Autohotkey can't handle this:
Code: Select all
gui, add, text, , Type here:
gui, add, edit, x+5 w100 vUserType, 1+1
gui, add, button, x+5 gcalculate, Calculate
gui, add, text, xm, Result:
gui, add, edit, x+5 w100 vresult,
gui, show, , Calculator
return
calculate:
gui, submit, nohide
calculation := %UserType%
guicontrol, , result, %calculation%
return
guiclose:
exitapp
Re: Easy calculator
thank you for support
Re: Easy calculator
Silvex3000 wrote:
When using ':=' the line would be:
calculation := UserType
Your script runs as expected with:
calculation = %UserType%
Most prefer the former syntax. Learning when to use %var% vs just the variable name is key to using AHK.
Relayer
edit: I may have missed that you wanted the expression evaluated and not simply echoed. I think you are having that discussion in another thread. Good day!
Don't be disappointed. The issue is with this line.I'm in Shock (very disappointed with AutoHotkey)
AutoHotkey has two equal signs: '=' and ':='calculation := %UserType%
When using ':=' the line would be:
calculation := UserType
Your script runs as expected with:
calculation = %UserType%
Most prefer the former syntax. Learning when to use %var% vs just the variable name is key to using AHK.
Relayer
edit: I may have missed that you wanted the expression evaluated and not simply echoed. I think you are having that discussion in another thread. Good day!
-
- Posts: 112
- Joined: 06 Jun 2016, 21:32
Re: Easy calculator
"calculation = %UserType%"
That also not working.. Relayer,
is there any other option??
That also not working.. Relayer,
is there any other option??
Re: Easy calculator [Updated 2018-07-29] Topic is solved
AHKv1
AHKv2
⠀
⠀
Eval function (Updates): https://github.com/flipeador/Library-AutoHotkey/blob/master/math/Eval.ahk.
Related (JS Big): https://github.com/flipeador/Library-AutoHotkey/blob/master/math/Big.ahk.
Code: Select all
; Updates —> https://github.com/flipeador/Library-AutoHotkey/blob/master/math/Eval.ahk
; ===================================================================================================
; GUI
; ===================================================================================================
Gui Add, Text, x5 y5 w300 h21, Expression to calculate:
Gui Add, Edit, x5 y30 w300 vUserType, 2 * PI * abs(-2)
Gui Add, Text, x5 y70 w300 h21, Result:
Gui Add, Edit, x5 y95 w300 vResult
Gui Add, Button, x5 y125 w300 gCalculate Default, Calculate
Gui Show,, AutoHotkey Simple Calculator
return
; ===================================================================================================
; LABELS
; ===================================================================================================
Calculate:
Gui Submit, NoHide
GuiControl ,, Result, % Eval(UserType)
return
GuiClose:
Exitapp
; ===================================================================================================
; FUNCTIONS
; ===================================================================================================
Eval(Expr, Format := FALSE)
{
static obj := "" ; par cuestiones de rendimiento
if ( !obj )
obj := ComObjCreate("HTMLfile")
Expr := StrReplace( RegExReplace(Expr, "\s") , ",", ".")
, Expr := RegExReplace(StrReplace(Expr, "**", "^"), "(\w+(\.*\d+)?)\^(\w+(\.*\d+)?)", "pow($1,$3)") ; 2**3 -> 2^3 -> pow(2,3)
, Expr := RegExReplace(Expr, "=+", "==") ; = -> == | === -> == | ==== -> == | ..
, Expr := RegExReplace(Expr, "\b(E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2)\b", "Math.$1")
, Expr := RegExReplace(Expr, "\b(abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)\b\(", "Math.$1(")
, obj.write("<body><script>document.body.innerText=eval('" . Expr . "');</script>")
, Expr := obj.body.innerText
return InStr(Expr, "d") ? "" : InStr(Expr, "false") ? FALSE ; d = body | undefined
: InStr(Expr, "true") ? TRUE
: ( Format && InStr(Expr, "e") ? Format("{:f}",Expr) : Expr )
} ; CREDITS (tidbit) - https://autohotkey.com/boards/viewtopic.php?f=6&t=15389
AHKv2
Code: Select all
; Updates —> https://github.com/flipeador/Library-AutoHotkey/blob/master/math/Eval.ahk
; ===================================================================================================
; GUI
; ===================================================================================================
Gui := GuiCreate("+ToolWindow", "AutoHotkey Simple Calculator")
Gui.AddText("x5 y5 w300 h21", "Expression to calculate:")
Input := Gui.AddEdit("x5 y30 w300", "2 * PI * abs(-2)")
Gui.AddText("x5 y70 w300 h21", "Result:")
Output := Gui.AddEdit("x5 y95 w300")
Gui.AddButton("x5 y125 w300 Default", "Calculate").OnEvent("Click", (*) => Output.Text := Eval(Input.Text))
Gui.Show()
return
; ===================================================================================================
; FUNCTIONS
; ===================================================================================================
Eval(Expr, Format := FALSE)
{
static obj := ""
if ( !obj )
obj := ComObjCreate("HTMLfile")
Expr := StrReplace( RegExReplace(Expr, "\s") , ",", ".")
, Expr := RegExReplace(StrReplace(Expr, "**", "^"), "(\w+(\.*\d+)?)\^(\w+(\.*\d+)?)", "pow($1,$3)") ; 2**3 -> 2^3 -> pow(2,3)
, Expr := RegExReplace(Expr, "=+", "==") ; = -> == | === -> == | ==== -> == | ..
, Expr := RegExReplace(Expr, "\b(E|LN2|LN10|LOG2E|LOG10E|PI|SQRT1_2|SQRT2)\b", "Math.$1")
, Expr := RegExReplace(Expr, "\b(abs|acos|asin|atan|atan2|ceil|cos|exp|floor|log|max|min|pow|random|round|sin|sqrt|tan)\b\(", "Math.$1(")
, obj.write("<body><script>document.body.innerText=eval('" . Expr . "');</script>")
, Expr := obj.body.innerText
return InStr(Expr, "d") ? "" : InStr(Expr, "false") ? FALSE ; d = body | undefined
: InStr(Expr, "true") ? TRUE
: ( Format && InStr(Expr, "e") ? Format("{:f}",Expr) : Expr )
} ; CREDITS (tidbit) - https://autohotkey.com/boards/viewtopic.php?f=6&t=15389
⠀
⠀
Eval function (Updates): https://github.com/flipeador/Library-AutoHotkey/blob/master/math/Eval.ahk.
Related (JS Big): https://github.com/flipeador/Library-AutoHotkey/blob/master/math/Big.ahk.
-
- Posts: 112
- Joined: 06 Jun 2016, 21:32
Re: Easy calculator
yeah this is working,
thank you Flipeador!!
thank you Flipeador!!
Re: Easy calculator
Hallo,
try:
try:
Code: Select all
InputBox, Calc, Calculation, type your Calculation e.g.: 7+Sqrt(17)
FileDelete, A.ahk
FileAppend, ClipBoard := %Calc%, A.ahk
RunWait, A.ahk
MsgBox,, Result, %Calc% = %ClipBoard%
Re: Easy calculator
thank you for examples ,
@Rohwedder, short example with input , similar here from user 'Laszlo' :
@Rohwedder, short example with input , similar here from user 'Laszlo' :
Code: Select all
;- calculator user Laszlo 20050214
;https://autohotkey.com/board/topic/8751-minimalist-calculator-and-enhancements/
file=%a_scriptdir%\test.ahk
Gui,font,s14,Lucida Console
c=2*sqrt(16)
Gui,show,w440 h120,Calculator_Laszlo
Gui,add,edit, x10 y10 w400 h50 vEd1,%c%
Gui,add,button,gClear,Clear
Guicontrol,1:Focus,Ed1
send,^{end}
return
Guiclose:
exitapp
clear:
GuiControl,1:,ed1,
Guicontrol,1:Focus,Ed1
return
~$enter::
GuiControlGet,c,,ed1
FileDelete %file% ; delete old temporary file -> write new
FileAppend #NoTrayIcon`nFileDelete %file%`nFileAppend `% %c%`, %file%, %file%
RunWait %A_AhkPath% %file% ; run AHK to execute temp script, evaluate expression
FileRead, Result, %file% ; get result
FileDelete %file%
GuiControl,1:,ed1,%c%=%Result%
return
Who is online
Users browsing this forum: Google [Bot] and 339 guests