I could use some help writing a code for a simple calculator(similar to Microsoft Windows).
my code so far:
Code: Select all
#SingleInstance, Force
gui, +alwaysontop
answer := "0"
history := ""
gui, show, x3100 y700 h500 w285, Calculator
gui, font, s20 , arial
gui, add, text, x0 y10 h30 w285 right border 0x200 vHistory cAqua, %history%
gui, font, s20, arial
gui, add, text, x0 y40 h30 w285 right border 0x200 vAnswer, %answer%
gui, add, button, x0 y80 h70 w70 gCalculate, `%
gui, add, button, x+1 y80 h70 w70 gCalculate, √
;~ gui, add, button, x+1 y80 h70 w70 gCalculate, x²
;~ gui, add, button, x+1 y80 h70 w70 gCalculate, 1/x
gui, add, button, x0 y150 h70 w70 gCalculate, E
gui, add, button, x+1 y150 h70 w70 gCalculate, C
gui, add, button, x+1 y150 h70 w70 gCalculate, <X
gui, add, button, x+1 y150 h70 w70 gCalculate, ÷
gui, add, button, x0 y220 h70 w70 gCalculate, 7
gui, add, button, x+1 y220 h70 w70 gCalculate, 8
gui, add, button, x+1 y220 h70 w70 gCalculate, 9
gui, add, button, x+1 y220 h70 w70 gCalculate, x
gui, add, button, x0 y290 h70 w70 gCalculate, 4
gui, add, button, x+1 y290 h70 w70 gCalculate, 5
gui, add, button, x+1 y290 h70 w70 gCalculate, 6
gui, add, button, x+1 y290 h70 w70 gCalculate, ─
gui, add, button, x0 y360 h70 w70 gCalculate, 1
gui, add, button, x+1 y360 h70 w70 gCalculate, 2
gui, add, button, x+1 y360 h70 w70 gCalculate, 3
gui, add, button, x+1 y360 h70 w70 gCalculate, +
gui, add, button, x0 y430 h70 w70 gCalculate, ±
gui, add, button, x+1 y430 h70 w70 gCalculate, 0
gui, add, button, x+1 y430 h70 w70 gCalculate, .
gui, add, button, x+1 y430 h70 w70 gCalculate, =
return
Calculate:
GuiControlGet, var,, % A_GuiControl
if(var == "C")
Reload
else if(var == "=")
GoSub, Result
GuiControl,, Answer, % var
tempHistory .= var
return
Result:
GuiControl,, History, % tempHistory
IfInString, tempHistory, +
{
Loop, parse, tempHistory, +
{
var += %A_LoopField%
}
answer = % var
}
else IfInString, tempHistory, ─
{
Loop, parse, tempHistory, ─
{
var = %A_LoopField%
}
answer = % var1 - var2
}
else if(var == "x")
{
answer = % var * var
}
else if(var == "÷")
{
answer = % (var1 / var3)
}
GuiControl,, Answer, % var
return
return
GuiClose:
ExitApp
any help is greatly appreciated!
cheers
yawikflame