Пятница, 10.01.2025, 13:37
Приветствую Вас Гость | RSS

MyCalc

Option Explicit
Dim Op1 As Double, Op2 As Double
Dim DecimalFlag As Boolean
Dim LastInput As String
Dim Z As String
Const Equals As Integer = 4

Private Sub Form_Load()
    DecimalFlag = False
    LastInput = "NONE"
    Z = ""
    Readout = Format(0, "0.")
End Sub

Private Sub Number_Click(Index As Integer)
If LastInput <> "NUMS" Then
                Readout = Format(0, ".")
                DecimalFlag = False
        End If
        If DecimalFlag Then
            Readout = Readout + Number(Index).Caption
        Else
            Readout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + _
            Number(Index).Caption + Format(0, ".")
            End If
            LastInput = "NUMS"
End Sub

Private Sub Neg_Click()
If Val(Readout) >= 0 Then
    Readout = "-" & Readout
Else
    Readout = Mid(Readout, 2)
End If
End Sub

Private Sub Operator_Click(Index As Integer)
If LastInput = "NUMS" Then
    If Z = "" Then
        Op1 = Readout
    Else
        Op2 = Readout
        Select Case Z
                Case "+"
                Op1 = CDbl(Op1) + CDbl(Op2)
                Case "-"
                Op1 = CDbl(Op1) - CDbl(Op2)
                Case "*"
                Op1 = CDbl(Op1) * CDbl(Op2)
                Case "/"
                    If Op2 = 0 Then
                        MsgBox "Delit' na NOLI nelizea!", 48, "Calculator"
                        Else
                            Op1 = CDbl(Op1) / CDbl(Op2)
                        End If
                End Select
                Readout = Op1
            End If
        End If
        If Index = Equals Then
            Z = ""
        Else
            Z = Operator(Index).Caption
        End If
        LastInput = "OPS"
End Sub

Private Sub Decimal_Click()
If LastInput <> "NUMS" Then
    Readout = Format(0, "0.")
    LastInput = "NUMS"
End If
    DecimalFlag = True
End Sub

Private Sub Cancel_Click()
Op1 = 0
Op2 = 0
Z = ""
DecimalFlag = False
LastInput = "NONE"
Readout = Format(0, "0.")
End Sub

Private Sub Number_1_Click()

End Sub

Private Sub Readout_Change()

End Sub