Akhirnya selesai juga bisa mengerjakan jawaban untuk soal yang pertama mata kuliah Pemrograman Visual
Desain Form
Kode Program
Public Class Form1
Sub tabel()
With lv
.Columns.Add("No. Pembelian", 100, HorizontalAlignment.Left)
.Columns.Add("Kode Barang", 100, HorizontalAlignment.Left)
.Columns.Add("Nama Barang", 180, HorizontalAlignment.Center)
.Columns.Add("Merk", 100, HorizontalAlignment.Center)
.Columns.Add("Harga", 100, HorizontalAlignment.Center)
.Columns.Add("Jumlah Beli", 100, HorizontalAlignment.Left)
.Columns.Add("Total Harga", 100, HorizontalAlignment.Left)
.GridLines = True
.View = View.Details
.FullRowSelect = True
End With
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tabel()
kodebarang.Items.Add("TS001")
kodebarang.Items.Add("TS002")
kodebarang.Items.Add("VG001")
kodebarang.Items.Add("VG002")
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
End
End Sub
Private Sub kodebarang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kodebarang.SelectedIndexChanged
Dim x As String
x = Microsoft.VisualBasic.Left(kodebarang.Text, 2)
If x = "TS" Then
merk.Text = "Toshiba"
ElseIf x = "VG" Then
merk.Text = "V-Gen"
End If
x = Microsoft.VisualBasic.Right(kodebarang.Text, 3)
If x = "001" Then
namabarang.Text = "Flashdisk 4GB"
ElseIf x = "002" Then
namabarang.Text = "Flashdisk 2GB"
End If
x = Microsoft.VisualBasic.Left(kodebarang.Text, 5)
If x = "TS001" Then
harga.Text = 105000
ElseIf x = "TS002" Then
harga.Text = 75000
ElseIf x = "VG001" Then
harga.Text = 90000
Else
harga.Text = 60000
End If
End Sub
Private Sub jumbeli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumbeli.KeyPress
If Asc(e.KeyChar) = 13 Then
total.Text = jumbeli.Text * harga.Text
End If
End Sub
Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
Dim lst As New ListViewItem
lst.Text = nopem.Text
lst.SubItems.Add(kodebarang.Text)
lst.SubItems.Add(namabarang.Text)
lst.SubItems.Add(merk.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jumbeli.Text)
lst.SubItems.Add(total.Text)
lv.Items.Add(lst)
End Sub
Private Sub bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bersih.Click
nopem.Text = ""
kodebarang.Text = ""
namabarang.Text = ""
merk.Text = ""
harga.Text = ""
jumbeli.Text = ""
total.Text = ""
End Sub
Private Sub hapusemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapusemua.Click
lv.Items.Clear()
End Sub
Private Sub hapusygdipilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapusygdipilih.Click
lv.Items.Remove(lv.SelectedItems(0))
End Sub
End Class