Sie sind auf Seite 1von 3

Option Explicit

Dim Operand1, Operand2 As Double


Dim Operator As String
Dim ClearDisplay As Boolean

Private Sub Clear_Click()


Display.Caption = “”

End Sub

Private Sub ClearBttn_Click()


Display.Caption = “”

End Sub

Private Sub CosineBttn_Click()


Display.Caption = Cos(Val(Display.Caption))
Display.Caption = Format(Val(Display.Caption), “#.00″)

End Sub

Private Sub Digits_Click(Index As Integer)


If ClearDisplay Then
Display.Caption = “”
ClearDisplay = False
End If
Display.Caption = Display.Caption + Digits(Index).Caption
End Sub

Private Sub DivBttn_Click()


Operand1 = Val(Display.Caption)
Operator = “/”
Display.Caption = “”
End Sub

Private Sub EqualsBttn_Click()


Dim result As Double
Operand2 = Val(Display.Caption)
If Operator = “+” Then result = Operand1 + Operand2
If Operator = “-” Then result = Operand1 – Operand2
If Operator = “*” Then result = Operand1 * Operand2
If Operator = “/” And Operand2 “0” Then result = Operand1 / Operand2
Display.Caption = result

End Sub
Private Sub LogBttn_Click()
If Display.Caption < 0 Then
MsgBox "Can't calculate the logarithm of a negative number"
Else
Display.Caption = Log(Val(Display.Caption))
End If
Display.Caption = Format(Val(Display.Caption), "#.00")

End Sub

Private Sub MinusBttn_Click()


Operand1 = Val(Display.Caption)
Operator = "-"
Display.Caption = ""

End Sub

Private Sub PercentBttn_Click()


Display.Caption = Val(Display.Caption) / 100
Display.Caption = Format(Val(Display.Caption), "#.00")

End Sub

Private Sub PlusBttn_Click()


Operand1 = Val(Display.Caption)
Operator = "+"
Display.Caption = ""

End Sub

Private Sub SineBttn_Click()


Display.Caption = Sin(Val(Display.Caption))
Display.Caption = Format(Val(Display.Caption), "#.00")

End Sub

Private Sub SquarerootBttn_Click()


If Display.Caption < 0 Then
MsgBox "Can't calculate the square root of a negative number"
Else
Display.Caption = Sqr(Val(Display.Caption))
Display.Caption = Format(Val(Display.Caption), "#.00")

End If

End Sub
Private Sub TangentBttn_Click()
Display.Caption = Tan(Val(Display.Caption))
Display.Caption = Format(Val(Display.Caption), "#.00")

End Sub

Private Sub TimesBttn_Click()


Operand1 = Val(Display.Caption)
Operator = "*"
Display.Caption = ""
End Sub

Das könnte Ihnen auch gefallen