Minggu, 02 Juni 2013

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

Selesaikanlah Kasus Berikut :
JUDUL SOAL


Berikut Jawaban Program :

Soal No.1


Coding program:

Public Class Form1

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

        Addbuattabel()

        AddKodeBarang()

        AddHapus(Me)

        AddNoPembelian()

        Button1.Enabled = False

        Button2.Enabled = False

        Button3.Enabled = False

    End Sub

    Sub AddHapus(ByVal f As Form)

        nourut.Text = ""

        kb.Text = ""

        nb.Text = ""

        m.Text = ""

        Harga.Text = ""

        Jumlah.Text = ""

        Total_harga.Text = ""

        nb.ReadOnly = True

        Harga.ReadOnly = True

        m.ReadOnly = True

        'Dim ctl As Control

        'For Each ctl In f.Controls

        'If TypeOf ctl Is TextBox Then ctl.Text = ""

        'If TypeOf ctl Is ComboBox Then ctl.Text = ""

        'Next

    End Sub

    Sub AddNoPembelian()

        For i = 1 To 50

            nourut.Items.Add(i)

        Next

      

    End Sub

    Sub AddKodeBarang()

        kb.Items.Add("TS001")

        kb.Items.Add("TS002")

        kb.Items.Add("VG001")

        kb.Items.Add("VG002")

        kb.Items.Add("KG001")

        kb.Items.Add("KG002")

    End Sub

    Sub Addbuattabel()

        lv.Items.Clear()

        With lv

            .GridLines = True

            .FullRowSelect = True

            .View = View.Details

            .Columns.Add("No")

            .Columns.Add("Kode Barang", 100)

            .Columns.Add("Nama Barang", 150)

            .Columns.Add("Merek", 120)

            .Columns.Add("Harga", 130)

            .Columns.Add("Jumlah", 100)

            .Columns.Add("Total", 130)

        End With

    End Sub

    Sub AddIsiTabel()

        Dim lst As New ListViewItem

        With lst

            .Text = nourut.Text

            .SubItems.Add(kb.Text)

            .SubItems.Add(nb.Text)

            .SubItems.Add(m.Text)

            .SubItems.Add(Harga.Text)

            .SubItems.Add(Jumlah.Text)

            .SubItems.Add(Format(Harga.Text * Jumlah.Text))

        End With

        lv.Items.Add(lst)

        CekTotal()

    End Sub

 

    Sub CekTotal()

        Dim bobot As Long

        bobot = 0

        For i As Integer = 0 To LV.Items.Count - 1

            bobot = bobot + Val(lv.Items(i).SubItems(6).Text)

        Next

        TotalPenjualan.Text = "Rp. " & Format(bobot, "###,###,###")

    End Sub

 

    Private Sub kb_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kb.SelectedIndexChanged

        Dim x As String

        Dim a As String

        a = Microsoft.VisualBasic.Right(kb.Text, 3)

        x = Microsoft.VisualBasic.Left(kb.Text, 2)

        Select Case x

            Case "TS" : m.Text = "Toshiba"

                Select Case a

                    Case "001" : nb.Text = "Falshdisk 1GB" : Harga.Text = "10500"

                    Case "002" : nb.Text = "Flashdisk 2GB" : Harga.Text = "7500"

                End Select

            Case "VG" : m.Text = "V-Gen"

                Select Case a

                    Case "001" : nb.Text = "Falshdisk 4GB" : Harga.Text = "9000"

                    Case "002" : nb.Text = "Flashdisk 8GB" : Harga.Text = "6000"

                End Select

            Case "KG" : m.Text = "Kingston"

                Select Case a

                    Case "001" : nb.Text = "Falshdisk 12GB" : Harga.Text = "90000"

                    Case "002" : nb.Text = "Flashdisk 16GB" : Harga.Text = "120000"

                End Select

        End Select

        Jumlah.Focus()

        Button1.Enabled = True

        Button2.Enabled = True

        Button3.Enabled = True

    End Sub

 

    Private Sub lv_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lv.DoubleClick

        If lv.SelectedItems.Count <> 0 Then

            lv.Items.Remove(lv.SelectedItems(0))

        Else

            MsgBox("Pilih dulu list data yang dihapus")

        End If

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim i As Integer

        i = MsgBox("Anda Ingin Keluar?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Data Penjualan Mobil Toyota")

        If i = vbYes Then

            Close()

        End If

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        lv.Items.Remove(lv.SelectedItems(0))

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        AddHapus(Me)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        AddIsiTabel()

        AddHapus(Me)

    End Sub

 

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        lv.Items.Clear()

    End Sub

    Private Sub Jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Jumlah.KeyPress

        Total_harga.Text = Val(Harga.Text) * Val(Jumlah.Text)

    End Sub

 

End Class

 

 

SOAL NO.2

 

 

 

CODING PROGRAMNYA:

 

Public Class Form2

 

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        nama_barang.Items.Add("SONY KLD-32CX520")

        nama_barang.Items.Add("SONY KLV-40BX320")

        nama_barang.Items.Add("SONY KLV-40BX350")

        nama_barang.Items.Add("SONY KLV-40BX420")

    End Sub

 

    Private Sub nama_barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nama_barang.SelectedIndexChanged

        If nama_barang.Text = "SONY KLD-32CX520" Then

            harga.Text = 1990000

        ElseIf nama_barang.Text = "SONY KLV-40BX320" Then

            harga.Text = 590000

        ElseIf nama_barang.Text = "SONY KLV-40BX350" Then

            harga.Text = 536000

        ElseIf nama_barang.Text = "SONY KLV-40BX420" Then

            harga.Text = 910000

        End If

    End Sub

 

    Private Sub jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress

    

    End Sub

 

    Private Sub Proses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Proses.Click

        total_harga.Text = Val(harga.Text) * Val(jumlah.Text)

        If total_harga.Text >= 2500000 Then

            discount.Text = Val(total_harga.Text) * 0.1

            Total_pembayaran.Text = Val(total_harga.Text) - Val(discount.Text)

        Else

            discount.Text = 0

            Total_pembayaran.Text = total_harga.Text

        End If

    End Sub

 

    Private Sub Keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Keluar.Click

        Me.Close()

    End Sub

End Class

 

Selamat Pemrograman VB NET

 

Tidak ada komentar:

Poskan Komentar