Advanced Calculator

Building An Advanced Calculator Program

Code:

Option Explicit
Dim FirstNumber As Single
Dim SecondNumber As Single
Dim AnswerNumber As Single
Dim ArithmeticProcess As String

Private Sub CommandButton1_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “7”

Else

txtDisplay.Text = txtDisplay.Text & “7”

End If
End Sub

Private Sub CommandButton10_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “+”
End Sub

Private Sub CommandButton11_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “-”
End Sub

Private Sub CommandButton12_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “+/-”
End Sub

Private Sub CommandButton13_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “×”
End Sub

Private Sub CommandButton14_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “÷”
End Sub

Private Sub CommandButton15_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “6”

Else

txtDisplay.Text = txtDisplay.Text & “6”

End If
End Sub

Private Sub CommandButton16_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “9”

Else

txtDisplay.Text = txtDisplay.Text & “9”

End If
End Sub

Private Sub CommandButton17_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “2”

Else

txtDisplay.Text = txtDisplay.Text & “2”

End If
End Sub

Private Sub CommandButton18_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “5”

Else

txtDisplay.Text = txtDisplay.Text & “5”

End If
End Sub

Private Sub CommandButton19_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “8”

Else

txtDisplay.Text = txtDisplay.Text & “8”

End If
End Sub

Private Sub CommandButton2_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “3”

Else

txtDisplay.Text = txtDisplay.Text & “3”

End If
End Sub

Private Sub CommandButton20_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “0”

Else

txtDisplay.Text = txtDisplay.Text & “0”

End If
End Sub

Private Sub CommandButton21_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “1”

Else

txtDisplay.Text = txtDisplay.Text & “1”

End If
End Sub

Private Sub CommandButton22_Click()
If txtDisplay.Text = “0” Then
txtDisplay.Text = “4”

Else

txtDisplay.Text = txtDisplay.Text & “4”

End If
End Sub

Private Sub CommandButton3_Click()
txtDisplay.Text = 0
End Sub

Private Sub CommandButton4_Click()
txtDisplay = Left(txtDisplay, Len(txtDisplay) – 1)
End Sub

Private Sub CommandButton5_Click()
SecondNumber = Val(txtDisplay.Text)
If ArithmeticProcess = “+” Then
AnswerNumber = FirstNumber + SecondNumber
End If
If ArithmeticProcess = “1/x” Then
AnswerNumber = 1 / FirstNumber
End If
If ArithmeticProcess = “%” Then
AnswerNumber = FirstNumber / 100
End If
If ArithmeticProcess = “v” Then
AnswerNumber = Sqr(FirstNumber)
End If
If ArithmeticProcess = “-” Then
AnswerNumber = FirstNumber – SecondNumber
End If
If ArithmeticProcess = “×” Then
AnswerNumber = FirstNumber * SecondNumber
End If
If ArithmeticProcess = “÷” Then
AnswerNumber = FirstNumber / SecondNumber
End If
If ArithmeticProcess = “+/-” Then
AnswerNumber = FirstNumber * -1
End If
txtDisplay.Text = AnswerNumber
End Sub

Private Sub CommandButton6_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “1/x”
End Sub

Private Sub CommandButton7_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “%”
End Sub

Private Sub CommandButton8_Click()
FirstNumber = Val(txtDisplay.Text)
txtDisplay.Text = “0”
ArithmeticProcess = “v”
End Sub

Private Sub CommandButton9_Click()
txtDisplay.Text = txtDisplay.Text & “.”
End Sub

Advanced Calculator in Microsoft Excel 2007

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: