Jumat, 06 April 2012

Coding Calculator


Public Class Form1
    Dim A As Integer = 1
    Dim BilPertama As Double
    Dim BilKedua As Double
    Dim Penghitungan As String
    Dim Hasil As Double

    Private Sub Button1_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "1"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "1"
        End If
    End Sub

    Private Sub Button2_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "2"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "2"
        End If
    End Sub

    Private Sub Button3_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "3"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "3"
        End If
    End Sub

    Private Sub Button4_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "4"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "4"
        End If
    End Sub

    Private Sub Button5_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "5"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "5"
        End If
    End Sub

    Private Sub Button6_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "6"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "6"
        End If
    End Sub

    Private Sub Button7_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "7"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "7"
        End If
    End Sub

    Private Sub Button8_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "8"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "8"
        End If
    End Sub

    Private Sub Button9_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "9"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "9"
        End If
    End Sub

    Private Sub Button10_Click
        If Txthasil.Text = "0" Or A = 0 Then
            Txthasil.Text = "0"
            A = 1
        Else
            Txthasil.Text = Txthasil.Text & "0"
        End If
    End Sub

    Private Sub Button11_Click
        If BilPertama <> 0 Or BilKedua <> 0 Or Hasil <> 0 Then
            BilPertama = 0
            BilKedua = 0
            Hasil = 0
        End If
        Txthasil.Text = "0"
    End Sub

    Private Sub Button12_Click
        BilPertama = Val(Txthasil.Text)
        Penghitungan = "+"
        A = 0
    End Sub

    Private Sub Button13_Click
        BilPertama = Val(Txthasil.Text)
        Penghitungan = "-"
        A = 0
    End Sub

    Private Sub Button14_Click
        BilPertama = Val(Txthasil.Text)
        Penghitungan = "*"
        A = 0
    End Sub

    Private Sub Button15_Click
        BilPertama = Val(Txthasil.Text)
        Penghitungan = "/"
        A = 0
    End Sub

    Private Sub Button16_Click
        BilPertama = Val(Txthasil.Text)
        Penghitungan = "^"
        A = 0
    End Sub

    Private Sub Button17_Click
        hitung()
    End Sub
    Sub hitung()
        BilKedua = Val(Txthasil.Text)
        If Penghitungan = "+" Then
            Hasil = BilPertama + BilKedua
        End If
        If Penghitungan = "-" Then
            Hasil = BilPertama - BilKedua
        End If
        If Penghitungan = "*" Then
            Hasil = BilPertama * BilKedua
        End If
        If Penghitungan = "/" Then
            If BilKedua = 0 Then
                Hasil = BilPertama
            Else
                Hasil = BilPertama / BilKedua
            End If
        End If
        If Penghitungan = "^" Then
            Hasil = BilPertama ^ BilKedua

        End If
        Txthasil.Text = Hasil
        A = 0
    End Sub
End Class

Tinggalkan Komentar Anda Untuk Memperbaiki Isi Blog ini

Tidak ada komentar:

Posting Komentar