Sabtu, 01 Juni 2013

Yuk! Belajar Pemrograman Visual Basic dot Net Di Mesran.Net

Judul Soal : 

 Kasus Pemrograman Pemakaian Listrik


Berikut adalah Jawaban Design dan Program

Public Class Form1
    Sub addKodePelanggan()
        With kd_pelanggan
            .Items.Add("TOK-MED-01")
            .Items.Add("TOK-BEL-02")

            .Items.Add("TOK-TEM-03")
            .Items.Add("TOK-MAR-04")
            .Items.Add("TOK-BIN-05")
            .Items.Add("TOK-PAK-06")
            .Items.Add("RUM-MED-07")
            .Items.Add("RUM-BEL-08")
            .Items.Add("RUM-TEM-09")
            .Items.Add("RUM-MAR-10")
            .Items.Add("RUM-BIN-11")
            .Items.Add("RUM-PAK-12")
            .Items.Add("SWA-MED-13")
            .Items.Add("SWA-BEL-14")
            .Items.Add("SWA-TEM-15")
            .Items.Add("SWA-MAR-16")
            .Items.Add("SWA-BIN-17")
            .Items.Add("SWA-PAK-18")
            .Items.Add("PAB-MED-19")
            .Items.Add("PAB-BEL-20")
            .Items.Add("PAB-TEM-21")
            .Items.Add("PAB-MAR-22")
            .Items.Add("PAB-BIN-23")
            .Items.Add("PAB-PAK-24")
        End With
    End Sub
    Sub rancang_tabel()
        With LV
            .Columns.Add("Kode Pelanggan", 100, HorizontalAlignment.Center)
            .Columns.Add("Besar Pemakaian", 100, HorizontalAlignment.Left)
            .Columns.Add("Pajak", 100, HorizontalAlignment.Left)
            .Columns.Add("Total Tagihan", 100, HorizontalAlignment.Left)
            .Columns.Add("Total Pembayaran", 100, HorizontalAlignment.Left)
            .FullRowSelect = True
            .GridLines = True
            .View = View.Details
        End With
    End Sub
    Sub isitabel()
        Dim x As New ListViewItem
        x.Text = kd_pelanggan.Text
        x.SubItems.Add(Besar_Pakai.Text)
        x.SubItems.Add(pajak.Text)
        x.SubItems.Add(total_tagih.Text)
        x.SubItems.Add(total_bayar.Text)
        LV.Items.Add(x)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call addKodePelanggan()
        rancang_tabel()
    End Sub

    Private Sub kd_pelanggan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kd_pelanggan.SelectedIndexChanged
        Dim x As String
        Dim y As String
        y = Microsoft.VisualBasic.Mid(kd_pelanggan.Text, 5, 3)
        x = Microsoft.VisualBasic.Left(kd_pelanggan.Text, 3)
        If x = "TOK" Then
            tipe.Text = "Toko"
        ElseIf x = "RUM" Then
            tipe.Text = "Rumah"
        ElseIf x = "SWA" Then
            tipe.Text = "Swalayan"
        Else
            tipe.Text = "Pabrik"
        End If
        If y = "MED" Then
            daerah.Text = "Medan"
        ElseIf y = "BEL" Then
            daerah.Text = "Belawan"
        ElseIf y = "TEM" Then
            daerah.Text = "Aksara"
        ElseIf y = "MAR" Then
            daerah.Text = "Marendal"
        ElseIf y = "BIN" Then
            daerah.Text = "Binjai"
        Else
            daerah.Text = "Lubuk Pakam"
        End If
    End Sub

    Private Sub tipe_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tipe.TextChanged
        If tipe.Text = "Toko" Then
            beban.Text = 150000
            hargakwh.Text = 500
        ElseIf tipe.Text = "Rumah" Then
            beban.Text = 50000
            hargakwh.Text = 200
        ElseIf tipe.Text = "Swalayan" Then
            beban.Text = 400000
            hargakwh.Text = 1500
        Else
            beban.Text = 1000000
            hargakwh.Text = 10000
        End If
    End Sub


    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
        kd_pelanggan.Text = ""
        daerah.Text = ""
        tipe.Text = ""
        beban.Text = ""
        hargakwh.Text = ""
        Besar_Pakai.Text = ""
        kini.Text = ""
        lalu.Text = ""
        pajak.Text = ""
        total_bayar.Text = ""
        total_tagih.Text = ""
    End Sub

    Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
        Me.Close()
    End Sub

    Private Sub proses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles proses.Click
        Besar_Pakai.Text = Val(kini.Text - lalu.Text)
        total_tagih.Text = Val(beban.Text) + Val(hargakwh.Text) * Val(Besar_Pakai.Text)
        pajak.Text = 0.015 * Val(total_tagih.Text)
        total_bayar.Text = Val(pajak.Text) + Val(total_tagih.Text)
    End Sub

    Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        isitabel()
        hapus_Click(sender, e)
    End Sub
End Class
dan hasilnya adalah :


Demikilahlah postingan saya  Nama : (DWI RISKI PURNAMASARI)  NPM : (1111240)
Selamat Pemrograman VB NET 

0 komentar:

Posting Komentar

Template by:

Free Blog Templates