第21講 電卓の高度化その1
第6話 メモリーボタンコーティング例
コーティング例
Dim w As Double, v As Double
, x As Double
, h As Byte, k As Byte, a As Integer, b As Byte    

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()       
  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

Private Sub CommandButton18_Click()
  k = 1
  a = 0
End Sub
Private Sub CommandButton19_Click()
  x = 0
End Sub
Private Sub CommandButton20_Click()
  w = x
  TextBox1.Text = w
End Sub
Private Sub CommandButton21_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
  x = x + v
  w = 0
  k = 0
  a = 0
  v = 0
End Sub

Private Sub CommandButton22_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
  x = x - v
  w = 0
  k = 0
  a = 0
  v = 0
End Sub


簡単な動作テストをやって正常に動くことを確認していますが、
実験が不十分なので不具合があるかもしれません。
もし、不具合を見つけた場合、大変お手数ですがメールしていただけると幸いに思います。
尚、プログラムについてよりよいものを考えた方は、メール等で教えていただければと思います。
私のぼんくらな頭では、出来の悪いプログラムしか思い浮かばないからです。


ダウンロード用参考ファイル

第5話へ 第22講第1話へ

004
  

VBA講義第1部へ
vc++講義へ
vb講義へ
VB講義基礎へ
初心者のための世界で一番わかりやすいVisual C++入門基礎講座へ
初心者のための世界で一番わかりやすいVisual Basic入門基礎講座へ

数学研究室に戻る