Minggu, 02 Juni 2013

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

Latihan Listview Perhitungan Penjualan Barang

Berikut Jawaban Program :
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BuatTabel()
        Kode.Items.Add("TS001")
        Kode.Items.Add("TS002")
        Kode.Items.Add("VG001")
        Kode.Items.Add("VG002")
    End Sub
    Sub BuatTabel()
        lv.Columns.Add("No. Pembelian", 100, HorizontalAlignment.Center)
        lv.Columns.Add("Kode Barang", 100, HorizontalAlignment.Center)
        lv.Columns.Add("Nama Barang", 100, HorizontalAlignment.Center)
        lv.Columns.Add("Merk", 80, HorizontalAlignment.Center)
        lv.Columns.Add("Harga", 80, HorizontalAlignment.Center)
        lv.Columns.Add("Jumlah Beli", 80, HorizontalAlignment.Center)
        lv.Columns.Add("Total Harga", 90, 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 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
            Jumlah_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 Kode_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 BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
        End
    End Sub

    Private Sub Bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bersih.Click
        No.Text = ""
        Kode.Text = ""
        Nama.Text = ""
        Merk.Text = ""
        Harga.Text = ""
        Jumlah.Text = ""
        Total.Text = ""
    End Sub

    Private Sub HapusSemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HapusSemua.Click
        lv.Items.Clear()
    End Sub

    Private Sub Hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hapus.Click
        lv.Items.Remove(lv.SelectedItems(0))
    End Sub

    Private Sub BtnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSimpan.Click
        IsiTable()
    End Sub
End Class

Hasil program :


Demikilahlah postingan saya 
Nama : Awaluddin
NPM : 1111084

Selamat Pemrograman VB NET

Tidak ada komentar: