Senin, 25 Januari 2016

UJIAN AKHIR SEMESTER MEMBUAT PROGRAM KALKULATOR SEDERHANA CARA 1

UJIAN AKHIR SEMESTER MEMBUAT PROGRAM KALKULATOR SEDERHANA
Berikut adalah coding cara membuat calculator : 
Public Class Form1
    Dim nilai, hasil, angka As Integer
    Dim simbol As String
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        hasil = txthasilcalculator.Text
        simbol = "+"
        txthasilcalculator.Text = ""
       
    End Sub
   
  
    Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
        End
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click

    End Sub


    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "1"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "1"
        End If
        Me.Button14.Text = "&1"
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "7"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "7"
        End If
        Me.Button5.Text = "&7"
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "8"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "8"
        End If
        Me.Button6.Text = "&8"
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "9"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "9"
        End If
        Me.Button7.Text = "&9"
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "4"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "4"
        End If
        Me.Button9.Text = "&4"
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "5"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "5"
        End If
        Me.Button10.Text = "&5"
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "6"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "6"
        End If
        Me.Button11.Text = "&6"
    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "2"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "2"
        End If
        Me.Button15.Text = "&2"
    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "3"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "3"
        End If
        Me.Button16.Text = "&3"
    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        If txthasilcalculator.Text = "0" Then
            txthasilcalculator.Text = "0"
        Else : txthasilcalculator.Text = txthasilcalculator.Text & "0"
        End If
        Me.Button18.Text = "&0"
    End Sub

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click

        If simbol = "+" Then
            hasil = nilai + Val(txthasilcalculator.Text)
            txthasilcalculator.Text = hasil
        ElseIf simbol = "-" Then
            hasil = nilai - Val(txthasilcalculator.Text)
            txthasilcalculator.Text = hasil
        ElseIf simbol = "X" Then
            hasil = nilai * Val(txthasilcalculator.Text)
            txthasilcalculator.Text = hasil
        ElseIf simbol = "/" Then
            hasil = nilai / Val(txthasilcalculator.Text)
            txthasilcalculator.Text = hasil
        End If
    End Sub

    Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
        If txthasilcalculator.Text = "," Then
            txthasilcalculator.Text = ","
        Else : txthasilcalculator.Text = txthasilcalculator.Text & ","
        End If
        Me.Button19.Text = "&."
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        nilai = txthasilcalculator.Text
        simbol = "-"
        txthasilcalculator.Text = ""
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        nilai = txthasilcalculator.Text
        simbol = "/"
        txthasilcalculator.Text = ""
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Me.txthasilcalculator.Clear()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        nilai = txthasilcalculator.Text
        simbol = "X"
        txthasilcalculator.Text = ""
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If txthasilcalculator.Text.Length <> 0 Then
            txthasilcalculator.Text = txthasilcalculator.Text.Remove(txthasilcalculator.TextLength - 1, 1)
        End If
    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        txthasilcalculator.Text = "-" & Val(txthasilcalculator.Text)
    End Sub
End Class
MOHON MAAF JIKA TERDAPAT KESALAHAN DALAM CODING 

Tidak ada komentar:

Posting Komentar