Rabu, 05 Juni 2013

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

Selesaikan kasus berikut :

latihan listview perhitungan penjualan barang


Berikut Jawabannya :





Listing Program :


Public Class Form1

    Sub BuatTabel()
        LV.Columns.Add("No Pembelian", 120, HorizontalAlignment.Center)
        LV.Columns.Add("Kode Barang", 120, HorizontalAlignment.Center)
        LV.Columns.Add("Nama Barang", 120, HorizontalAlignment.Center)
        LV.Columns.Add("Merk", 100, HorizontalAlignment.Center)
        LV.Columns.Add("Harga", 100, HorizontalAlignment.Center)
        LV.Columns.Add("Jumlah Beli", 120, HorizontalAlignment.Center)
        LV.Columns.Add("Total Harga", 100, HorizontalAlignment.Center)
        LV.View = View.Details
        LV.GridLines = True
        LV.FullRowSelect = True
    End Sub
    Sub IsiTable()
        Dim Lst As New ListViewItem
        Lst.Text = no.Text
        Lst.SubItems.Add(kode.Text)
        Lst.SubItems.Add(nama.Text)
        Lst.SubItems.Add(merk.Text)
        Lst.SubItems.Add(harga.Text)
        Lst.SubItems.Add(jumlah.Text)
        Lst.SubItems.Add(total.Text)
        LV.Items.Add(Lst)
    End Sub
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode.SelectedIndexChanged
        Dim x As String
        x = Microsoft.VisualBasic.Left(kode.Text, 2)
        If x = "TS" Then
            merk.Text = "Thosiba"
        ElseIf x = "VG" Then
            merk.Text = "V-Gen"
        End If
        x = Microsoft.VisualBasic.Right(kode.Text, 3)
        If x = "001" Then
            nama.Text = "Flashdisk 4GB"
        ElseIf x = "002" Then
            nama.Text = "Flashdisk 2GB"
        End If
        If kode.Text = "TS001" Then
            harga.Text = "105000"
        ElseIf kode.Text = "TS002" Then
            harga.Text = "75000"
        ElseIf kode.Text = "VG001" Then
            harga.Text = "90000"
        ElseIf kode.Text = "VG002" Then
            harga.Text = "60000"
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BuatTabel()
        kode.Items.Add("TS001")
        kode.Items.Add("TS002")
        kode.Items.Add("VG001")
        kode.Items.Add("VG002")
    End Sub
    Private Sub total_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles total.TextChanged
    End Sub
Private Sub jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
        Dim tombol As Integer = Asc(e.KeyChar)
        If tombol = 13 Then
            total_TextChanged(sender, e)
            total.Text = jumlah.Text * harga.Text
        End If
    End Sub

    Private Sub jumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jumlah.TextChanged

    End Sub
    Private Sub BtnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSimpan.Click
        IsiTable()
        No.Text = ""
        kode.Text = ""
        nama.Text = ""
        merk.Text = ""
        harga.Text = ""
        jumlah.Text = ""
        total.Text = ""
    End Sub

    Private Sub BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        LV.Items.Clear()
    End Sub

    Private Sub BtnData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnData.Click
        LV.Items.Remove(LV.SelectedItems(0))
    End Sub

    Private Sub BtnBersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBersih.Click
        No.Text = ""
        kode.Text = ""
        nama.Text = ""
        merk.Text = ""
        harga.Text = ""
        jumlah.Text = ""
        total.Text = ""
    End Sub

    Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
        End
    End Sub
End Class

Maka hasilnya seperti gambar dibawah ini :





Demikilahlah postingan saya  Nama : SONI SUGIARTO  NPM : 1111115
Selamat Pemrograman VB NET

Tidak ada komentar: