# Calculator!

## Recommended Posts

Here is a calculator, because i searched the forum and not enough were written. I tried to write this as efficiently as possible and make it easy to understand so here! Hope ya like it let me know of any improvements!

```#NoTrayIcon
#include <guiconstants.au3>
#include <EditConstants.au3>
;calculator created by isaac flaum
Guicreate("Calc", 105, 130)
\$i = 0
\$input = GUICtrlCreateInput("", 5, 5, 95, 20, \$ES_READONLY)
\$7 = guictrlcreatebutton("7", 5, 30, 20, 20)
\$8 = guictrlcreatebutton("8", 30, 30, 20, 20)
\$9 = guictrlcreatebutton("9", 55, 30, 20, 20)
\$4 = guictrlcreatebutton("4", 5, 55, 20, 20)
\$5 = guictrlcreatebutton("5", 30, 55, 20, 20)
\$6 = guictrlcreatebutton("6", 55, 55, 20, 20)
\$1 = guictrlcreatebutton("1", 5, 80, 20, 20)
\$2 = guictrlcreatebutton("2", 30, 80, 20, 20)
\$3 = guictrlcreatebutton("3", 55, 80, 20, 20)
\$equals = guictrlcreatebutton("=", 5, 105, 20, 20)
\$0 = guictrlcreatebutton("0", 30, 105, 20, 20)
\$operation = 4 ;0 = plus, 1 = minus, 2 = times, 3 = divide, 4 = nothing
\$clear = guictrlcreatebutton("C", 55, 105, 20, 20)
\$divide = guictrlcreatebutton("/", 80, 30, 20, 20)
\$multiply = guictrlcreatebutton("x", 80, 55, 20, 20)
\$plus = guictrlcreatebutton("+", 80, 80, 20, 20)
\$minus = guictrlcreatebutton("-", 80, 105, 20, 20)
guisetstate(@SW_SHOW)
Do
\$msg = guigetmsg()
if (\$msg =  -3) Then
\$i = 1
EndIf

Select
Case(\$msg = \$0)
guictrlsetdata(\$input, \$pnum & "0")
Case(\$msg = \$1)
guictrlsetdata(\$input, \$pnum & "1")
Case(\$msg = \$2)
guictrlsetdata(\$input, \$pnum & "2")
Case(\$msg = \$3)
guictrlsetdata(\$input, \$pnum & "3")
Case(\$msg = \$4)
guictrlsetdata(\$input, \$pnum & "4")
Case(\$msg = \$5)
guictrlsetdata(\$input, \$pnum & "5")
Case(\$msg = \$6)
guictrlsetdata(\$input, \$pnum & "6")
Case(\$msg = \$7)
guictrlsetdata(\$input, \$pnum & "7")
Case(\$msg = \$8)
guictrlsetdata(\$input, \$pnum & "8")
Case(\$msg = \$9)
guictrlsetdata(\$input, \$pnum & "9")
Case (\$msg = \$plus)
\$operation = 0
guictrlsetdata(\$input, "")
Case (\$msg = \$minus)
\$operation = 1
guictrlsetdata(\$input, "")
Case (\$msg = \$multiply)
\$operation = 2
guictrlsetdata(\$input, "")
Case (\$msg = \$divide)
\$operation = 3
guictrlsetdata(\$input, "")
Case (\$msg = \$equals)
if \$operation = 0 Then
Elseif \$operation = 1 Then
_subtract()
Elseif \$operation = 2 Then
_multiply()
Elseif \$operation = 3 Then
_divide()
Else

EndIf
\$operation = 4
Case (\$msg = \$clear)
\$num1 = 0
\$num2 = 0
guictrlsetdata(\$input, "")

EndSelect

Until \$i = 1

\$final = \$num1 + \$num2
guictrlsetdata(\$input, \$final)
EndFunc

func _subtract()
\$final = \$num1 - \$num2
guictrlsetdata(\$input, \$final)
EndFunc

func _multiply()
\$final = (\$num1 * \$num2)
guictrlsetdata(\$input, \$final)
EndFunc

func _divide()
\$final = (\$num1 / \$num2)
guictrlsetdata(\$input, \$final)
EndFunc```

`global \$warming = true`

##### Share on other sites

Bravo, Very Nice!! The first one I think I have seen on here that does not show the calculation like 25*3=75..I like it! Thanks for sharing...

##### Share on other sites

It's works great and looks good. I just have to use a magnifing glass. Just kidding, but it is kinda tiny. That is better than my LCARS calculator which is a full screen app.

Anyone who does not wonder is either omniscient or foolish.

##### Share on other sites

I like it.

When the words fail... music speaks

##### Share on other sites

LimeSeed

Ha-ha! Very easy and nice!

Edited by rasim

##### Share on other sites

nice!, I made one 2, look my sig!

##### Share on other sites

Thanks :-) now i will add more functions! sorry it is so small, i just like my gui's small and organized!

`global \$warming = true`

## Create an account

Register a new account

×

• Wiki

• Back

• Git