回答編集履歴

1

追記

2021/09/11 16:02

投稿

jinoji
jinoji

スコア4592

test CHANGED
@@ -5,3 +5,249 @@
5
5
  でも、=を押した後に押すのが再び=の時は、entは0ではなくその直前の演算子であってほしい。
6
6
 
7
7
  そこを区別するための何かが必要ではないでしょうか。
8
+
9
+
10
+
11
+ ---
12
+
13
+
14
+
15
+ 試しに作ってみた。まだおかしなところはあるかも。
16
+
17
+
18
+
19
+ ```vba
20
+
21
+ Option Explicit
22
+
23
+
24
+
25
+ Dim a, x, b
26
+
27
+ Dim enzan As Boolean
28
+
29
+ Dim equal As Boolean
30
+
31
+
32
+
33
+ Private Sub CommandButton1_Click()
34
+
35
+ NumberKey "1"
36
+
37
+ End Sub
38
+
39
+ Private Sub CommandButton2_Click()
40
+
41
+ NumberKey "2"
42
+
43
+ End Sub
44
+
45
+ Private Sub CommandButton3_Click()
46
+
47
+ NumberKey "3"
48
+
49
+ End Sub
50
+
51
+ Private Sub CommandButton4_Click()
52
+
53
+ NumberKey "4"
54
+
55
+ End Sub
56
+
57
+ Private Sub CommandButton5_Click()
58
+
59
+ NumberKey "5"
60
+
61
+ End Sub
62
+
63
+ Private Sub CommandButton6_Click()
64
+
65
+ NumberKey "6"
66
+
67
+ End Sub
68
+
69
+ Private Sub CommandButton7_Click()
70
+
71
+ NumberKey "7"
72
+
73
+ End Sub
74
+
75
+ Private Sub CommandButton8_Click()
76
+
77
+ NumberKey "8"
78
+
79
+ End Sub
80
+
81
+ Private Sub CommandButton9_Click()
82
+
83
+ NumberKey "9"
84
+
85
+ End Sub
86
+
87
+ Private Sub CommandButton10_Click()
88
+
89
+ NumberKey "0"
90
+
91
+ End Sub
92
+
93
+ Private Sub CommandButton17_Click() '00ボタン
94
+
95
+ NumberKey "00"
96
+
97
+ End Sub
98
+
99
+ Private Sub CommandButton19_Click() '小数点
100
+
101
+ TextBox1.Text = TextBox1.Text & "."
102
+
103
+ End Sub
104
+
105
+ Sub NumberKey(key As String)
106
+
107
+ TextBox1.Text = IIf(enzan, key, Str(TextBox1.Text & key))
108
+
109
+ enzan = False
110
+
111
+ b = TextBox1.Text
112
+
113
+ End Sub
114
+
115
+
116
+
117
+
118
+
119
+ Private Sub CommandButton11_Click() '+  足し算
120
+
121
+ enzan = True
122
+
123
+ If a = "" Or equal Then
124
+
125
+ a = TextBox1.Text
126
+
127
+ equal = False
128
+
129
+ Else
130
+
131
+ calc
132
+
133
+ End If
134
+
135
+ x = "+"
136
+
137
+ End Sub
138
+
139
+ Private Sub CommandButton12_Click() '- 引き算
140
+
141
+ enzan = True
142
+
143
+ If a = "" Or equal Then
144
+
145
+ a = TextBox1.Text
146
+
147
+ equal = False
148
+
149
+ Else
150
+
151
+ calc
152
+
153
+ End If
154
+
155
+ x = "-"
156
+
157
+ End Sub
158
+
159
+
160
+
161
+ Private Sub CommandButton13_Click() '* 掛け算
162
+
163
+ enzan = True
164
+
165
+ If a = "" Or equal Then
166
+
167
+ a = TextBox1.Text
168
+
169
+ equal = False
170
+
171
+ Else
172
+
173
+ calc
174
+
175
+ End If
176
+
177
+ x = "*"
178
+
179
+ End Sub
180
+
181
+ Private Sub CommandButton14_Click() '/  割り算
182
+
183
+ enzan = True
184
+
185
+ If a = "" Or equal Then
186
+
187
+ a = TextBox1.Text
188
+
189
+ equal = False
190
+
191
+ Else
192
+
193
+ calc
194
+
195
+ End If
196
+
197
+ x = "/"
198
+
199
+ End Sub
200
+
201
+
202
+
203
+ Function calc()
204
+
205
+ Select Case x
206
+
207
+ Case "+": a = CDbl(a) + CDbl(b)
208
+
209
+ Case "-": a = CDbl(a) - CDbl(b)
210
+
211
+ Case "*": a = CDbl(a) * CDbl(b)
212
+
213
+ Case "/": a = CDbl(a) / CDbl(b)
214
+
215
+ End Select
216
+
217
+ TextBox1.Text = a
218
+
219
+ End Function
220
+
221
+
222
+
223
+ Private Sub CommandButton15_Click() 'イコールボタン ここで条件分岐
224
+
225
+ enzan = True
226
+
227
+ equal = True
228
+
229
+ calc
230
+
231
+ End Sub
232
+
233
+
234
+
235
+ Private Sub CommandButton18_Click() 'クリアボタン
236
+
237
+ TextBox1.Text = ""
238
+
239
+ End Sub
240
+
241
+ Private Sub CommandButton16_Click() 'オールクリア
242
+
243
+ a = ""
244
+
245
+ x = ""
246
+
247
+ TextBox1.Text = "0"
248
+
249
+ End Sub
250
+
251
+
252
+
253
+ ```