1) I didn't know how to create percentage button
2) after it gives result, i want it to clear the result with pressing any number button.
Please help me to find out the solution!
Thank you for your time!
Option Explicit
Dim UpToDateCalculation As Double
Dim Times As Boolean
Dim Add As Boolean
Dim TakeAway As Boolean
Dim Divide As Boolean
Dim Equals As Boolean
Private Sub cmd0_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "0"
Else
txtDisplay.Text = txtDisplay.Text & "0"
End If
End Sub
Private Sub cmd1_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "1"
Else
txtDisplay.Text = txtDisplay.Text & "1"
End If
End Sub
Private Sub cmd2_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "2"
Else
txtDisplay.Text = txtDisplay.Text & "2"
End If
End Sub
Private Sub cmd3_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "3"
Else
txtDisplay.Text = txtDisplay.Text & "3"
End If
End Sub
Private Sub cmd4_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "4"
Else
txtDisplay.Text = txtDisplay.Text & "4"
End If
End Sub
Private Sub cmd5_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "5"
Else
txtDisplay.Text = txtDisplay.Text & "5"
End If
End Sub
Private Sub cmd6_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "6"
Else
txtDisplay.Text = txtDisplay.Text & "6"
End If
End Sub
Private Sub cmd7_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "7"
Else
txtDisplay.Text = txtDisplay.Text & "7"
End If
End Sub
Private Sub cmd8_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "8"
Else
txtDisplay.Text = txtDisplay.Text & "8"
End If
End Sub
Private Sub cmd9_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "9"
Else
txtDisplay.Text = txtDisplay.Text & "9"
End If
End Sub
Private Sub cmdClear_Click()
UpToDateCalculation = 0
txtDisplay.Text = 0
Add = False
TakeAway = False
Times = False
Divide = False
Equals = False
End Sub
Private Sub cmdCos_Click(Index As Integer)
txtDisplay.Text = Math.Cos(txtDisplay.Text)
End Sub
Private Sub cmdDivision_Click(Index As Integer)
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
txtDisplay.Text = "0"
Else
If txtDisplay.Text = 0 Then
Else
UpToDateCalculation = UpToDateCalculation / Val(txtDisplay.Text)
txtDisplay.Text = "0"
End If
End If
Add = False
TakeAway = False
Times = False
Divide = True
End Sub
Private Sub cmdDot_Click(Index As Integer)
If InStr(txtDisplay.Text, ".") = 0 Then
txtDisplay.Text = txtDisplay.Text & "."
End If
End Sub
Private Sub cmdEqual_Click(Index As Integer)
If Add = True Then
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
txtDisplay.Text = "0"
Else
UpToDateCalculation = UpToDateCalculation + Val(txtDisplay.Text)
End If
Else
If TakeAway = True Then
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
Else
UpToDateCalculation = UpToDateCalculation - Val(txtDisplay.Text)
End If
Else
If Times = True Then
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
Else
UpToDateCalculation = UpToDateCalculation * Val(txtDisplay.Text)
End If
Else
If Divide = True Then
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
Else
If txtDisplay.Text = 0 Then
Else
UpToDateCalculation = UpToDateCalculation / Val(txtDisplay.Text)
End If
End If
End If
End If
End If
End If
txtDisplay.Text = UpToDateCalculation
Add = False
TakeAway = False
Times = False
Divide = False
Equals = True
End Sub
Private Sub cmdMinus_Click(Index As Integer)
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
txtDisplay.Text = "0"
Else
If txtDisplay.Text = 0 Then
Else
UpToDateCalculation = UpToDateCalculation - Val(txtDisplay.Text)
txtDisplay.Text = "0"
End If
End If
Add = False
TakeAway = True
Times = False
Divide = False
End Sub
Private Sub cmdmultiplication_Click(Index As Integer)
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
txtDisplay.Text = "0"
Else
If txtDisplay.Text = 0 Then
Else
UpToDateCalculation = UpToDateCalculation * Val(txtDisplay.Text)
txtDisplay.Text = "0"
End If
End If
Add = False
TakeAway = False
Times = True
Divide = False
End Sub
Private Sub cmdPercentage_Click(Index As Integer)
End Sub
Private Sub cmdPi_Click(Index As Integer)
If (txtDisplay.Text = 0) Then
txtDisplay.Text = "3.1415926"
Else
txtDisplay.Text = txtDisplay.Text & "3.1415926"
End If
End Sub
Private Sub cmdPlus_Click(Index As Integer)
If UpToDateCalculation = 0 Then
UpToDateCalculation = Val(txtDisplay.Text)
txtDisplay.Text = "0"
Else
UpToDateCalculation = UpToDateCalculation + Val(txtDisplay.Text)
txtDisplay.Text = "0"
End If
Add = True
TakeAway = False
Times = False
Divide = False
End Sub
Private Sub cmdSin_Click(Index As Integer)
Select Case Index
Dim x As Double
Case 0
x = Val(txtDisplay.Text)
txtDisplay.Text = Round((Sin(x * 3.14159265 / 180)), 4)
End Select
End Sub
Private Sub cmdSqrt_Click(Index As Integer)
txtDisplay.Text = Math.Sqr(txtDisplay.Text)
End Sub
Private Sub cmdTan_Click(Index As Integer)
txtDisplay.Text = Math.Tan(txtDisplay.Text)
End Sub

New Topic/Question
Reply



MultiQuote



|