Kamis, 06 Juni 2013

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






Public Class Form1

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

    Private Sub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode.SelectedIndexChanged
        Dim x, Y As String
        x = Microsoft.VisualBasic.Left(kode.Text, 2)
        Y = Microsoft.VisualBasic.Right(kode.Text, 3)

        Select Case x
            Case "TS" : merk.Text = "THOSIBA"
            Case "VG" : merk.Text = "v-gen"
        End Select
        Select Case Y
            Case "001" : nama.Text = "flashdisk 4 GG"
            Case "002" : nama.Text = "flashdisk 2 GG"

        End Select
        If x = "TS" And Y = "001" Then
            harga.Text = 105000
        ElseIf x = "TS" And Y = "002" Then
            harga.Text = 75000
        ElseIf x = "VG" And Y = "001" Then
            harga.Text = 90000
        ElseIf x = "VG" And Y = "002" Then
            harga.Text = 60000
        Else
            harga.Text = 0
        End If
    End Sub

    Private Sub total_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles total.TextChanged
        total.Text = Val(harga.Text) * Val(jumlah.Text)
    End Sub

    Private Sub jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
        Dim x1 As Integer = Asc(e.KeyChar)

        If x1 = 13 Then
            total.Text = Val(harga.Text) * Val(jumlah.Text)

        End If

    End Sub

   
    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", 100, HorizontalAlignment.Center)

        Lv.Columns.Add("harga", 100, HorizontalAlignment.Center)
        Lv.Columns.Add("jumlah beli", 100, HorizontalAlignment.Center)

        Lv.Columns.Add("total harga", 100, HorizontalAlignment.Center)
        Lv.View = View.Details
        Lv.GridLines = True
        Lv.FullRowSelect = True


    End Sub

    Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        isitabel()
    End Sub
    Sub isitabel()
        Dim lst As New ListViewItem
        lst.Text = kode.Text
        lst.SubItems.Add(nopem.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 hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
        Lv.Items.Clear()
    End Sub

    Private Sub pilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pilih.Click
        Lv.Items.Remove(Lv.SelectedItems(0))
    End Sub

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

dan hasilnya sbagai berikut :


Tidak ada komentar:

Posting Komentar