Private FirstNumber As Long ' Store user-defined numbers
Private SecondNumber As Long
Private Operation As Integer ' Store operation type
Private Sub button1_Click()
Me.TextBox1.Value = Me.TextBox1.Value & 1
End Sub
Private Sub button0_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 0 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 0
End Sub
Private Sub button9_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 9 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 9
End Sub
Private Sub button2_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 2 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 2
End Sub
Private Sub button7_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 7 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 7
End Sub
Private Sub button8_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 8 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 8
End Sub
Private Sub button5_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 5 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 5
End Sub
Private Sub button6_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 6 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 6
End Sub
Private Sub button3_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 3 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 3
End Sub
Private Sub button4_Click()
If Me.TextBox1.Value = 0 Then Me.TextBox1.Value = 4 _
Else Me.TextBox1.Value = Me.TextBox1.Value & 4
End Sub
Private Sub CommandAdd_Click()
FirstNumber = Me.TextBox1.Text ' Store first number
Me.TextBox1.Text = ""
Operation = 0 ' Select operation type
End Sub
Private Sub CommandSubtract_Click()
FirstNumber = Me.TextBox1.Text ' Store first number
Me.TextBox1.Text = ""
Operation = 1 ' Select operation type
End Sub
Private Sub CommandDivide_Click()
FirstNumber = Me.TextBox1.Text ' Store first number
Me.TextBox1.Text = ""
Operation = 2
End Sub
Private Sub CommandMultiply_Click()
FirstNumber = Me.TextBox1.Text ' Store first number
Me.TextBox1.Text = ""
Operation = 3
End Sub
Private Sub CommandEquals_Click()
SecondNumber = Me.TextBox1.Text ' Store second number
Select Case Operation ' Look to see what operation user selected
Case 0 ' Addition
Me.TextBox1.Text = FirstNumber + SecondNumber ' Perform operation
Case 1 ' Subtraction
Me.TextBox1.Text = FirstNumber - SecondNumber ' Perform operation
Case 2 ' Division
Me.TextBox1.Text = FirstNumber / SecondNumber ' Perform operation
Case 3 ' Multiplication
Me.TextBox1.Text = FirstNumber * SecondNumber ' Perform operation
End Select
End Sub
Private Sub Clear_Click() 'clears calculator
Me.TextBox1.Value = 0
FirstNumber = 0
SecondNumber = 0
End Sub