Jump to content

Calculator!


LimeSeed
 Share

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)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "0")
    Case($msg = $1)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "1")
    Case($msg = $2)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "2")
    Case($msg = $3)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "3")
    Case($msg = $4)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "4")
    Case($msg = $5)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "5")
    Case($msg = $6)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "6")
    Case($msg = $7)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "7")
    Case($msg = $8)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "8")
    Case($msg = $9)
        $pnum = guictrlread($input)
        guictrlsetdata($input, $pnum & "9")
    Case ($msg = $plus) 
        $num1 = guictrlread($input)
        $operation = 0
        guictrlsetdata($input, "")
    Case ($msg = $minus)
        $num1 = guictrlread($input)
        $operation = 1  
        guictrlsetdata($input, "")      
    Case ($msg = $multiply)
        $num1 = guictrlread($input)
        $operation = 2      
        guictrlsetdata($input, "")
    Case ($msg = $divide)
        $num1 = guictrlread($input)
        $operation = 3
        guictrlsetdata($input, "")
    Case ($msg = $equals)
        if $operation = 0 Then
            _add()
        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 

func _add()
    $num2 = guictrlread($input)
    $final = $num1 + $num2
    guictrlsetdata($input, $final)
EndFunc
    
func _subtract()
    $num2 = guictrlread($input)
    $final = $num1 - $num2
    guictrlsetdata($input, $final)
EndFunc
    
func _multiply()
    $num2 = guictrlread($input)
    $final = ($num1 * $num2)
    guictrlsetdata($input, $final)
EndFunc

func _divide()
    $num2 = guictrlread($input)
    $final = ($num1 / $num2)
    guictrlsetdata($input, $final)
EndFunc
global $warming = true
Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...