Jumat, 21 Oktober 2011

SCIENTIFIC CALCULATOR


Program kalkkulator ini saya buat karna ada tugas mata kuliah interaksi manusia dengan komputer mengenai desain sebuah program. Program ini bukan full buatan saya, saya hanya mengedit program yang sudah jadi menjadi lebih sempurna lagi. Tanpa banyak basa-basi saya akan segera menuliskan kodingan programnya. Sebelumnya mari kita buat desainnya.
    • Form1 --> Nama: <biarkan pada default>, Caption: SCIENTIFIC CALCULATOR
    • Option1 --> Nama: option1, Caption: deg, Index: 0
    • Option2 --> Nama: option1, Caption: rad, Index: 1
    • Option3 --> Nama: option1, Caption: grad, Index:2
    • Text1 --> Nama: <biarkan pada default>, Text: <kosongkan>
    • Text2 --> Nama: <biarkan pada default>, Text: <kosongkan>
    • command1 --> Nama: cmdon, Caption: ON
    • command2 --> Nama: cmdclear, Caption: AC
    • command3 --> Nama: cmdoff, Caption: OFF
    • Frame1 --> Caption: Operator
    • command4 --> Caption: cmd22, Nama: 1/X, Index:0
    • command5 --> Caption: cmd22, Nama: x2, Index:1
    • command6 --> Caption: cmd22, Nama: x3, Index:2
    • command7 --> Caption: cmd22, Nama: x!, Index:3
    • command8 --> Caption: cmd22, Nama: sqrt, Index:4
    • command9 --> Caption: cmd22, Nama: 10^x, Index:5
    • command10 --> Caption: cmd22, Nama: log, Index:6
    • command11 --> Caption: cmd22, Nama: ln, Index:7
    • command12 --> Caption: cmd22, Nama: e(x), Index:8
    • command13 --> Caption: cmd27, Nama: sin, Index:0
    • command14 --> Caption: cmd27, Nama: cos, Index:1
    • command15 --> Caption: cmd27, Nama: tan, Index:2
    • command16 --> Caption: cmd27, Nama: cosin, Index:3
    • command17 --> Caption: cmd27, Nama: sec, Index:4
    • command18 --> Caption: cmd27, Nama: cotan, Index:5
    • command19 --> Caption: cmdangka, Nama: 0, Index: 0
    • command20 --> Caption: cmdangka, Nama: 1, Index: 1
    • command21 --> Caption: cmdangka, Nama: 2, Index: 2
    • command22 --> Caption: cmdangka, Nama: 3, Index: 3
    • command23 --> Caption: cmdangka, Nama: 4, Index: 4
    • command24 --> Caption: cmdangka, Nama: 5, Index: 5
    • command25 --> Caption: cmdangka, Nama: 6, Index: 6
    • command26 --> Caption: cmdangka, Nama: 7, Index: 7
    • command27 --> Caption: cmdangka, Nama: 8, Index: 8
    • command28 --> Caption: cmdangka, Nama: 9, Index: 9
    • command29 --> Caption: cmdplusminus, Nama: +/-
    • command30 --> Caption: cmdkoma, Nama: .
    • command31 --> Caption: cmdop, Nama: +, Index: 0
    • command32 --> Caption: cmdop, Nama: -, Index: 1
    • command33 --> Caption: cmdop, Nama: *, Index: 2
    • command34 --> Caption: cmdop, Nama: /, Index: 3

    Dim ans, b, c, hasil, sudut As Double
    Dim a As String

    Dim i, X As Integer
    Dim no1 As Double, cnt1 As Integer
    Dim op As String, op1 As String


    Private Sub cmd22_Click(Index As Integer)
    Dim s1, s2, s3 As String
    op = "lain"
    s = Val(Text1.Text)
        Select Case Index
            Case 0
                Text2.Text = "1/" & s
                If s = 0 Then
                    Text1.Text = "            eror"
                ElseIf s <> 0 Then
                    Text1.Text = 1 / s
                End If
            If Val(tampilan.Caption) <> 0 Then tampilan.Caption = 1 / Val(tampilan.Caption)
            Case 1
                Text2.Text = s & "^(2)"
                Text1.Text = s ^ 2
            Case 2
                Text2.Text = s & "^(3)"
                Text1.Text = s ^ 3
                
            Case 3
                Dim n, f, k As Integer
                n = Text1.Text
                f = 1
                k = 1
                Text2.Text = Text2.Text & "!"
                If (n < 0) Then
                    Text1.Text = "salah input"
                ElseIf (n = 0) Then
                    Text1.Text = 1
                Else
                    Do While k <= n
                        f = f * k
                        k = k + 1
                    Loop
                Text1.Text = Str(f)
                End If
            Case 4
                Text2.Text = "sqr(" & s & ")"
                Text1.Text = Sqr(s)
            Case 5
                Text2.Text = "10^" & Text2.Text
                Text1.Text = 10 ^ (Val(Text1.Text))
            Case 6
                Text2.Text = "log(" & s & ")"
                 If Val(Text1.Text) > 0 Then
                    Text1.Text = Str((Log(Val(Text1.Text)) / Log(10)))
                 Else
                    Text1.Text = "error"
                 End If
            Case 7
               Text2.Text = "ln" & Text2.Text
               If Val(Text1.Text) > 0 Then
                    Text1.Text = Str(Log(Val(Text1.Text)))
                Else
                    Text1.Text = "error"
                 End If
            Case 8
                Text2.Text = "e^(x)" & Text2.Text
                If Val(Text1.Text) < 700 Then
                    Text1.Text = Str(Exp(Val(Text1.Text)))
                Else
                    MsgBox (" OVERFLOW. VALUE TOO BIG ")
                End If
        End Select

    End Sub

    Private Sub cmd27_Click(Index As Integer)
    s = Val(Text1.Text)
    sudut = 180 / 3.14159265358979
    Dim a, b, c As Single
        Select Case Index
        Case 0
            Text2.Text = "sin (" & Text2.Text & ")"
            Text1.Text = Sin(s / sudut)
        Case 1
            Text2.Text = "cos (" & Text2.Text & ")"
            If s = 90 Or s = 270 Then
                Text1.Text = 0
            Else
                Text1.Text = Cos(s / sudut)
            End If
        Case 2
            If s = 90 Or s = 270 Then
                Text1.Text = "error"
            Else
                a = Sin(s / sudut)
                b = Cos(s / sudut)
                c = a / b
                Text1.Text = c
            End If
            Text2.Text = "tan (" & Text2.Text & ")"
        Case 3
            If s = 90 Or s = 270 Then
                Text1.Text = "error"
            Else
                a = Sin(s / sudut)
                b = Cos(s / sudut)
                c = a / b
                Text1.Text = c
            End If
            Text2.Text = "tan (" & Text2.Text & ")"
        Case 4
            Text2.Text = "sec (" & Text2.Text & ")"
            If s = 90 Or s = 270 Then
                Text1.Text = 0
            Else
                Text1.Text = Cos(s / sudut)
            End If
        Case 5
            Text2.Text = "arc tan (" & Text2.Text & ")"
            Text1.Text = Str((Atn(Val(Text1.Text)) / (3.14159265358979 / 180)))
    End Select

    End Sub

    Private Sub cmd7_Click(Index As Integer)
    Select Case Index
            Case 0
                Memo = Memo + Val(Text1.Text)
            Case 1
                    Text1.Text = Str(Memo)
                    prev = Val(Text1.Text)
        End Select
    End Sub

    Private Sub cmdangka_Click(Index As Integer)
    If Text1.Text = "0" Then
        Text1.Text = ""
        End If
        If X = 0 Then
        Text1.Text = ""
        X = X + 1
        End If
        Text1.Text = Text1.Text + cmdangka(Index).Caption
        Text2.Text = Text2.Text + cmdangka(Index).Caption

    End Sub

    Private Sub cmdclear_Click()
    Select Case Index
        Case 0
            cnt1 = 0
            X = 0
            Text1.Text = ""
            Text2.Text = ""
            Text1.Visible = True
        Case 1
            Text2.Text = Mid(Text2.Text, 1, Len(Text2.Text) - 1)
        End Select

    End Sub


    Private Sub cmdkoma_Click()
    Text1.Text = Text1.Text + "."
    Text2.Text = Text2.Text + "."

    End Sub

    Private Sub cmdoff_Click()
    Unload Me
    End Sub

    Private Sub cmdon_Click()
    Text1.Visible = True
    Text2.Visible = True

    End Sub

    Private Sub cmdop_Click(Index As Integer)
    X = 0
        If cnt1 > 0 Then
            Select Case op
                Case "+"
                        ans = no1 + Text1.Text
                        Text1.Text = ans
                        no1 = Text1.Text
                        op = cmdop(Index).Caption
                Case "-"
                        ans = no1 - Text1.Text
                        Text1.Text = ans
                        no1 = Text1.Text
                        op = cmdop(Index).Caption
                Case "/"
                        ans = no1 / Text1.Text
                        Text1.Text = ans
                        no1 = Text1.Text
                        op = cmdop(Index).Caption
                Case "*"
                        ans = no1 * Val(Text1.Text)
                        Text1.Text = ans
                        no1 = Text1.Text
                        op = cmdop(Index).Caption
            End Select

        Else
        no1 = Val(Text1.Text)
        op = cmdop(Index).Caption
        cnt1 = cnt1 + 1
        End If
    Text2.Text = Text2.Text + cmdop(Index).Caption

    End Sub

    Private Sub cmdplusminus_Click()
    Text1.Text = Text1.Text * (-1)
    Text2.Text = Text2.Text * (-1)

    End Sub

    Private Sub cmdsmdgn_Click()
    cnt1 = 0
        Select Case op
            Case "+"
                    ans = Text1.Text + no1
                    If cnt = 0 Then
                      no1 = Text1.Text
                        cnt = cnt + 1
                    End If
                    Text1.Text = ans
        Case "-"
                    If cnt > 0 Then
                      Text1.Text = no1
                      no1 = ans
                    End If
                     ans = no1 - Text1.Text
                     no1 = Text1.Text
                     Text1.Text = ans
                    cnt = cnt + 1
            Case "*"
                    ans = no1 * Text1.Text
                    If cnt = 0 Then
                      no1 = Text1.Text
                        cnt = cnt + 1
                    End If
            Text1.Text = ans
            Case "/"
                    If cnt > 0 Then
                      Text1.Text = no1
                      no1 = ans
                    End If
                    If Text1.Text = "0" Then
                    i = MsgBox("Divide by zero error", vbExclamation + vbOKOnly, "ERROR")
                    Else
                    ans = no1 / Text1.Text
                     no1 = Text1.Text
                    Text1.Text = ans
                    cnt = cnt + 1
                    End If

        End Select
    Text1.Text = Text1.Text
    Text1.Visible = True

    End Sub

    Private Sub Option1_Click(Index As Integer)
    Select Case Index
                Case 0
                    ang = 3.141592654 / 180
                Case 1
                    ang = 1
                Case 2
                    ang = 3.141592654 / 200
                End Select
    End Sub




Tidak ada komentar:

Posting Komentar