質問編集履歴

2

数字入力の時のソースコード追加

2015/06/09 03:58

投稿

Strauss
Strauss

スコア32

test CHANGED
File without changes
test CHANGED
@@ -201,3 +201,55 @@
201
201
  ope = "-"
202
202
 
203
203
  End Sub
204
+
205
+
206
+
207
+ 追記いたします。
208
+
209
+ 各数字ボタンの入力は下記のようになっております。
210
+
211
+
212
+
213
+ '数字ボタン「1」クリック処理
214
+
215
+ Private Sub BtnOne_Click(sender As Object, e As EventArgs) Handles BtnOne.Click
216
+
217
+ 'エラー表示時の処理
218
+
219
+ If TextAns.Text = "E:桁数超過" Or TextAns.Text = "0で割ることはできません" Then
220
+
221
+ Exit Sub
222
+
223
+ End If
224
+
225
+
226
+
227
+ 'もし入力されたのが数字だった場合
228
+
229
+ If beforeIn >= "0" And beforeIn <= "9" Then
230
+
231
+ '直前で押されたのが数字ボタンだった場合
232
+
233
+ 'かつ、12桁未満の数値が入力されているとき
234
+
235
+ If TextAns.Text.Length < 13 Then
236
+
237
+ TextAns.Text &= "1"
238
+
239
+ Else
240
+
241
+ MsgBox("これ以上入力できません", 48, "警告メッセージ")
242
+
243
+ Exit Sub
244
+
245
+ End If
246
+
247
+ Else
248
+
249
+ TextAns.Text = "1"
250
+
251
+ End If
252
+
253
+ beforeIn = "1"
254
+
255
+ End Sub

1

問題部分のソースコードの追加

2015/06/09 03:58

投稿

Strauss
Strauss

スコア32

test CHANGED
File without changes
test CHANGED
@@ -13,3 +13,191 @@
13
13
 
14
14
 
15
15
  ぜひ、この部分だけでもご教授いただけたらと思います。
16
+
17
+
18
+
19
+ 追記
20
+
21
+ 問題のソース部分を記載します。
22
+
23
+
24
+
25
+ '「+」ボタンクリック処理
26
+
27
+ Private Sub BtnPlus_Click(sender As Object, e As EventArgs) Handles BtnPlus.Click
28
+
29
+ 'エラー表示時の処理
30
+
31
+ If TextAns.Text = "E:桁数超過" Then
32
+
33
+ Exit Sub
34
+
35
+ End If
36
+
37
+
38
+
39
+ '13桁以下なら計算可能
40
+
41
+ If TextAns.Text.Length < 13 Then
42
+
43
+ '前回入力されたのが数字の場合
44
+
45
+ If beforeIn >= "0" And beforeIn <= "9" Then
46
+
47
+ If ope = "C" Then
48
+
49
+ Ans = CType(TextAns.Text, Double)
50
+
51
+ Else
52
+
53
+ 'Ansに保存されている+ボタンクリック前の数値と加算
54
+
55
+ Num = CType(TextAns.Text, Double)
56
+
57
+ Ans = Ans + Num
58
+
59
+ '電卓の画面に表示
60
+
61
+ If TextAns.Text.Length >= 13 Then
62
+
63
+ TextAns.Text = "E:桁数超過"
64
+
65
+ Exit Sub
66
+
67
+ Else
68
+
69
+ TextAns.Text = Ans
70
+
71
+ End If
72
+
73
+ Else
74
+
75
+ '前回クリックされたボタンが数値以外の場合
76
+
77
+ Select Case ope
78
+
79
+ Case "C"
80
+
81
+ '前回がクリアボタン
82
+
83
+ Ans = CType(TextAns.Text, Double)
84
+
85
+ Case "="
86
+
87
+ '前回がイコールボタン
88
+
89
+ Ans = Ans + Num
90
+
91
+ Case "+", "-", "*", "/"
92
+
93
+
94
+
95
+ End Select
96
+
97
+ End If
98
+
99
+ Else
100
+
101
+ MsgBox("これ以上入力できません", 48, "警告メッセージ")
102
+
103
+ Exit Sub
104
+
105
+ End If
106
+
107
+ beforeIn = "+"
108
+
109
+ ope = "+"
110
+
111
+ End Sub
112
+
113
+
114
+
115
+ '「-」ボタンクリック処理
116
+
117
+ Private Sub BtnMinus_Click(sender As Object, e As EventArgs) Handles BtnMinus.Click
118
+
119
+ 'エラー表示時の処理
120
+
121
+ If TextAns.Text = "E:桁数超過" Then
122
+
123
+ Exit Sub
124
+
125
+ End If
126
+
127
+
128
+
129
+ '電卓上の数値が13桁以下なら処理可能
130
+
131
+ If TextAns.Text.Length < 13 Then
132
+
133
+ If beforeIn >= "0" And beforeIn <= "9" Then
134
+
135
+ If ope = "C" Then
136
+
137
+ '最初の数値をAnsに保存
138
+
139
+ Ans = CType(TextAns.Text, Double)
140
+
141
+ Else
142
+
143
+ 'Ansに保存されている-ボタンクリック前の数値と減算
144
+
145
+ Num = CType(TextAns.Text, Double)
146
+
147
+ Ans = Ans - Num
148
+
149
+ '電卓の画面に表示
150
+
151
+ If TextAns.Text.Length >= 13 Then
152
+
153
+ TextAns.Text = "E:桁数超過"
154
+
155
+ Exit Sub
156
+
157
+ Else
158
+
159
+ TextAns.Text = Ans
160
+
161
+ End If
162
+
163
+ End If
164
+
165
+ Else
166
+
167
+ '前回のクリックが数字以外の場合
168
+
169
+ Select Case ope
170
+
171
+ Case "C"
172
+
173
+ '前回がクリアボタン
174
+
175
+ Ans = CType(TextAns.Text, Double)
176
+
177
+ Case "="
178
+
179
+ '前回がイコールボタン
180
+
181
+ Ans = Ans - Num
182
+
183
+ Case "+", "-", "*", "/"
184
+
185
+
186
+
187
+ End Select
188
+
189
+ End If
190
+
191
+ Else
192
+
193
+ MsgBox("これ以上入力できません", 48, "警告メッセージ")
194
+
195
+ Exit Sub
196
+
197
+ End If
198
+
199
+ beforeIn = "-"
200
+
201
+ ope = "-"
202
+
203
+ End Sub