This repository has been archived by the owner on Oct 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.au3
135 lines (96 loc) · 3.68 KB
/
calculator.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
; Generated with GUI Maker http://trysohard.info/GUI-Maker/
; Copyright (C) 2016 Tryson Hardie.
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Local $hGUI = GUICreate("gui", 300, 360)
GUISetState(@SW_SHOW, $hGUI)
Local $txt = GUICtrlCreateEdit("", 20,20, 230,70)
Local $btClear = GUICtrlCreateButton("C", 20,100, 50,36)
Local $btplsMns = GUICtrlCreateButton("±", 80,100, 50,36)
Local $btsqrt = GUICtrlCreateButton("√", 140,100, 50,36)
Local $btpercent = GUICtrlCreateButton("%", 200,100, 50,36)
Local $bt7 = GUICtrlCreateButton("7", 20,145, 50,36)
Local $bt8 = GUICtrlCreateButton("8", 80,145, 50,36)
Local $btdiv = GUICtrlCreateButton("÷", 200,145, 50,36)
Local $bt9 = GUICtrlCreateButton("9", 140,145, 50,36)
Local $bt6 = GUICtrlCreateButton("6", 140,190, 50,36)
Local $bt5 = GUICtrlCreateButton("5", 80,190, 50,36)
Local $btmult = GUICtrlCreateButton("×", 200,190, 50,36)
Local $bt4 = GUICtrlCreateButton("4", 20,190, 50,36)
Local $btmns = GUICtrlCreateButton("-", 200,235, 50,36)
Local $bt1 = GUICtrlCreateButton("1", 20,235, 50,36)
Local $bt3 = GUICtrlCreateButton("3", 140,235, 50,36)
Local $bt2 = GUICtrlCreateButton("2", 80,235, 50,36)
Local $bt0 = GUICtrlCreateButton("0", 20,280, 50,36)
Local $btdot = GUICtrlCreateButton(".", 80,280, 50,36)
Local $btpls = GUICtrlCreateButton("+", 200,280, 50,36)
Local $btenter = GUICtrlCreateButton("=", 140,280, 50,36)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
;numbers
Case($bt0)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "0")
Case($bt1)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "1")
Case($bt2)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "2")
Case($bt3)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "3")
Case($bt4)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "4")
Case($bt5)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "5")
Case($bt6)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "6")
Case($bt7)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "7")
Case($bt8)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "8")
Case($bt9)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "9")
;operations
Case($btClear)
GuiCtrlSetData($txt, "")
Case($btplsMns)
$expr = GuiCtrlRead($txt)
$exprNeg = StringLeft($expr, 1)
If StringInStr($expr, "-", 0, 1, 1, 1) Then
GuiCtrlSetData($txt, StringTrimLeft ( $expr, 1 ))
Else
GuiCtrlSetData($txt, "-" & $expr)
EndIf
Case($btsqrt)
$expr = GuiCtrlRead($txt)
GuiCtrlSetData($txt, Execute(Sqrt($expr)))
Case($btpercent)
$expr = GuiCtrlRead($txt)
GuiCtrlSetData($txt, "(" & GuiCtrlRead($txt) & "/100)*")
Case($btpls)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "+")
Case($btmns)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "-")
Case($btmult)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "*")
Case($btdiv)
GuiCtrlSetData($txt, GuiCtrlRead($txt) & "/")
Case($btdot)
$expr = GuiCtrlRead($txt)
If StringIsDigit($expr) Then
GuiCtrlSetData($txt, $expr & ".") ; add dot to integer
ElseIf Not StringIsFloat($expr) Then ;2.2 + 2
$aAllNumbers = StringSplit($expr, "+|-|*|/") ; all possible delimiters
;_ArrayDisplay($aAllNumbers, 'numbers')
$aLastNumber = $aAllNumbers[$aAllNumbers[0]] ; the last number of expression
If StringIsDigit($aLastNumber) Then
GuiCtrlSetData($txt, $expr & "."); add dot to integer
EndIf
EndIf
Case($btenter)
$expr = GuiCtrlRead($txt)
GuiCtrlSetData($txt, Execute($expr))
EndSwitch
WEnd