[AutoIt] Simple Calculator 12-03-2011, 03:25 PM
#1
Code:
#include <EditConstants.au3>
#NoTrayIcon
Main()
Func Main()
GUIDelete()
$Main = GUICreate("Calculator by ReaperX", 300, 330)
$Input = GUICtrlCreateInput("", 10, 50, 280, 20, BitOr($ES_RIGHT, $GUI_SS_DEFAULT_INPUT, $ES_READONLY))
$C_Button = GUICtrlCreateButton("C", 185, 72, 50, 30)
$Evaluate = GUICtrlCreateButton("=", 235, 72, 50, 30)
$0_Button = GUICtrlCreateButton("0", 95, 270, 50, 30)
$1_Button = GUICtrlCreateButton("1", 35, 150, 50, 30)
$2_Button = GUICtrlCreateButton("2", 95, 150, 50, 30)
$3_Button = GUICtrlCreateButton("3", 155, 150, 50, 30)
$4_Button = GUICtrlCreateButton("4", 35, 190, 50, 30)
$5_Button = GUICtrlCreateButton("5", 95, 190, 50, 30)
$6_Button = GUICtrlCreateButton("6", 155, 190, 50, 30)
$7_Button = GUICtrlCreateButton("7", 35, 230, 50, 30)
$8_Button = GUICtrlCreateButton("8", 95, 230, 50, 30)
$9_Button = GUICtrlCreateButton("9", 155, 230, 50, 30)
$Plus_Button = GUICtrlCreateButton("+", 215, 150, 50, 30)
$Minus_Button = GUICtrlCreateButton("-", 215, 190, 50, 30)
$Times_Button = GUICtrlCreateButton("x", 215, 230, 50, 30)
$Divide_Button = GUICtrlCreateButton("/", 215, 270, 50, 30)
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
Exit
Case $0_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "0")
Case $1_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "1")
Case $2_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "2")
Case $3_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "3")
Case $4_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "4")
Case $5_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "5")
Case $6_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "6")
Case $7_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "7")
Case $8_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "8")
Case $9_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "9")
Case $C_Button
GUICtrlSetData($Input, "")
Case $Plus_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "+")
Case $Minus_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "-")
Case $Divide_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "/")
Case $Times_Button
GUICtrlSetData($Input, GUICtrlRead($Input) & "*")
Case $Evaluate
$Ans = Execute(GUICtrlRead($Input))
If @Error Then
MsgBox(16, "Error!", "Error Solving Equation!")
Main()
EndIf
If StringRight(GUICtrlRead($Input), 2) = "/0" Then
MsgBox(16, "Error!", "Divide By Zero Error!")
GUIDelete()
Main()
EndIf
GUICtrlSetData($Input, GUICtrlRead($Input) & " = " &$Ans)
EndSwitch
WEnd
EndFunc
(This post was last modified: 12-03-2011, 03:43 PM by Skullmeat.)



![[+]](https://sinister.li/images/modern/collapse_collapsed.png)
