第21講 電卓の高度化その1
第4話 ボタン×÷+−=のコーティング
解答例
Dim w As Double, v As Double, h As Byte, k As Byte, a As Integer, b As Byte '2012/04/14に間違いを訂正
Private Sub CommandButton18_Click()
k = 1
a = 0
End Sub
Private Sub CommandButton2_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 1
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w + 1
TextBox1.Text = w
End Sub
Private Sub CommandButton3_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 2
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w + 2
TextBox1.Text = w
End Sub
Private Sub CommandButton4_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 3
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w + 3
TextBox1.Text = w
End Sub
Private Sub CommandButton5_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 4
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w + 4
TextBox1.Text = w
End Sub
Private Sub CommandButton6_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 5
For i = 0 To a
w = w / 10
Next
a = a + 5
End If
If k = 0 Then w = 10 * w + 1
TextBox1.Text = w
End Sub
Private Sub CommandButton7_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 6
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w + 6
TextBox1.Text = w
End Sub
Private Sub CommandButton8_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 7
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w + 7
TextBox1.Text = w
End Sub
Private Sub CommandButton9_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
w = w + 8
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w + 8
TextBox1.Text = w
End Sub
Private Sub CommandButton10_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w
TextBox1.Text = w
End Sub
Private Sub CommandButton11_Click()
Dim i As Byte
If k = 1 Then
For i = 0 To a
w = 10 * w
Next
For i = 0 To a
w = w / 10
Next
a = a + 1
End If
If k = 0 Then w = 10 * w
TextBox1.Text = w
End Sub
Private Sub CommandButton12_Click()
TextBox1.Text = ""
w = 0
v = 0
k = 0
a = 0
b = 0
End Sub
Private Sub CommandButton13_Click() '2012/04/14に間違いを訂正
If b = 1 Then
If h = 1 Then
v = v * w
TextBox1.Text = v
End If
If h = 2 Then
v = v / w
TextBox1.Text = v
End If
If h = 3 Then
v = v + w
TextBox1.Text = v
End If
If h = 4 Then
v = v - w
TextBox1.Text = v
End If
Else
v = v + w
b = 1
End If
h = 1
w = 0
k = 0
a = 0
End Sub
Private Sub CommandButton14_Click()
If b = 1 Then
If h = 1 Then
v = v * w
TextBox1.Text = v
End If
If h = 2 Then
v = v / w
TextBox1.Text = v
End If
If h = 3 Then
v = v + w
TextBox1.Text = v
End If
If h = 4 Then
v = v - w
TextBox1.Text = v
End If
Else
v = v + w
b = 1
End If
h = 2
w = 0
k = 0
a = 0
End Sub
Private Sub CommandButton15_Click()
If b = 1 Then
If h = 1 Then
v = v * w
TextBox1.Text = v
End If
If h = 2 Then
v = v / w
TextBox1.Text = v
End If
If h = 3 Then
v = v + w
TextBox1.Text = v
End If
If h = 4 Then
v = v - w
TextBox1.Text = v
End If
Else
v = v + w
b = 1
End If
h = 3
w = 0
k = 0
a = 0
End Sub
Private Sub CommandButton16_Click()
If b = 1 Then
If h = 1 Then
v = v * w
TextBox1.Text = v
End If
If h = 2 Then
v = v / w
TextBox1.Text = v
End If
If h = 3 Then
v = v + w
TextBox1.Text = v
End If
If h = 4 Then
v = v - w
TextBox1.Text = v
End If
Else
v = v + w
b = 1
End If
h = 4
w = 0
k = 0
a = 0
End Sub
Private Sub CommandButton17_Click()
If h =
1 Then
v = v * w
TextBox1.Text = v
End If
If h = 2
Then
v = v / w
TextBox1.Text = v
End If
If h = 3
Then
v = v + w
TextBox1.Text = v
End If
If h = 4
Then
v = v - w
TextBox1.Text = v
End If
w = 0
k = 0
a = 0
b = 0
End
Sub
一応、小数点対応の電卓が完成しました。
次にメモリーの機能を付けましょう。
メモリーがつくと電卓の機能は飛躍的に増大します。
(3×15+48÷12)×(2×5+6)のような計算がメモなしでできるようになりますね。
ボタンを付けコーティングしてください。
第3話へ 第5話へ
VBA講義第1部へ
vc++講義へ
vb講義へ
VB講義基礎へ
初心者のための世界で一番わかりやすいVisual C++入門基礎講座へ
初心者のための世界で一番わかりやすいVisual Basic入門基礎講座へ
数学研究室に戻る