【Excel, VB】 電卓を作ろう
ソースの内容
---==---==---==---==---==---==---==---==---==---==---==---
------------------------------------------------ UserForm1
Dim btn(1 To 15) As New Class1
Private Sub UserForm_Initialize()
Dim ctlButton As Control
Dim i As Long
For i = 1 To 15
'コマンドボタン 1~15クラスモジュールに渡す
Set btn(i).myButton = Controls("CommandButton" & i)
Next i
End Sub
Private Sub CommandButton16_Click()
blnChk = True
TextBox1.Text = 0
End Sub
Private Sub CommandButton17_Click()
On Error GoTo er:
blnChk = True
TextBox1.Value = Application.Evaluate(TextBox1.Value)
Exit Sub
er:
TextBox1.Value = "エラー:" & Err
End Sub
---==---==---==---==---==---==---==---==---==---==---==---
---------------------------------------------------- Class1
Public WithEvents myButton As msforms.CommandButton
Private Sub myButton_Click()
If blnChk Then
blnChk = False
UserForm1.TextBox1.Text = vbNullString
End If
UserForm1.TextBox1.Text = UserForm1.TextBox1.Text & myButton.Caption
End Sub
---==---==---==---==---==---==---==---==---==---==---==---
--------------------------------------------------- Module1
Public blnChk As Boolean
Sub showUserform()
blnChk = True
UserForm1.TextBox1.Text = 0
UserForm1.Show
End Sub
---==---==---==---==---==---==---==---==---==---==---==---