listing program :
Public Class Form1
Private Sub kode_barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode_barang.SelectedIndexChanged
Dim X As String
X = Microsoft.VisualBasic.Left(kode_barang.Text, 2)
If X = "TS" Then
merek.Text = "TOSHIBA"
ElseIf X = "VG" Then
merek.Text = "V-GEN"
End If
X = Microsoft.VisualBasic.Right(kode_barang.Text, 3)
If X = "001" Then
nama_barang.Text = "FLASHDISK 4GB"
ElseIf X = "002" Then
nama_barang.Text = "FLASHDISK 2GB"
End If
harga.Text = Microsoft.VisualBasic.Right(kode_barang.Text, 5)
If kode_barang.Text = "TS001" Then
harga.Text = 105000
ElseIf kode_barang.Text = "TS002" Then
harga.Text = 75000
ElseIf kode_barang.Text = "VG001" Then
harga.Text = 90000
ElseIf kode_barang.Text = "VG002" Then
harga.Text = 60000
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
kode_barang.Items.Add("TS001")
kode_barang.Items.Add("TS002")
kode_barang.Items.Add("VG001")
kode_barang.Items.Add("VG002")
AddJumlah()
RancangTabel()
End Sub
Sub AddJumlah()
For i = 1 To 100
jumlah.Items.Add(i)
Next
End Sub
Sub Hapus()
no.Text = ""
nama_barang.Text = ""
kode_barang.Text = ""
merek.Text = ""
harga.Text = ""
jumlah.Text = ""
total.Text = ""
no.Focus()
End Sub
Private Sub jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
If e.KeyChar = Chr(13) Then
total.Text = harga.Text * jumlah.Text
End If
End Sub
Sub RancangTabel()
With LV
.Columns.Add("No.Pembelian", 80, HorizontalAlignment.Center)
.Columns.Add("kode barang", 120, HorizontalAlignment.Left)
.Columns.Add("nama barang", 60, HorizontalAlignment.Center)
.Columns.Add("merek", 80, HorizontalAlignment.Right)
.Columns.Add("harga", 100, HorizontalAlignment.Center)
.Columns.Add("jumlah beli", 80, HorizontalAlignment.Center)
.Columns.Add("total harga", 80, HorizontalAlignment.Right)
.View = View.Details
.GridLines = True
.FullRowSelect = True
End With
End Sub
Sub MasukTabel()
Dim lst As New ListViewItem
lst.Text = no.Text
lst.SubItems.Add(kode_barang.Text)
lst.SubItems.Add(nama_barang.Text)
lst.SubItems.Add(merek.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jumlah.Text)
lst.SubItems.Add(total.Text)
LV.Items.Add(lst)
End Sub
Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
MasukTabel()
End Sub
Private Sub hapus_semua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_semua.Click
Hapus()
End Sub
Private Sub hapus_dipilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_dipilih.Click
If LV.SelectedItems.Count <> 0 Then
LV.Items.Remove(LV.SelectedItems(0))
Else
MsgBox("Pilih terlebih dahulu baris data yang akan di hapus")
End If
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
End
End Sub
Private Sub bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bersih.Click
LV.Items.Clear()
End Sub
End Class
Hasil program :
untuk melihat soal : Klik disini
Jawaban soal 3 ( Beny wahono)
Listing program :
Public Class login
Private Sub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click
If user.Text = "beny" And password.Text = "12345" Then
menuutama.Show()
Me.Hide()
Else
MsgBox("data username/password salah?")
user.Text = ""
password.Text = ""
End If
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
End
End Sub
Hasil program :
Public Class menuutama
Private Sub TagihanPDAMToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TagihanPDAMToolStripMenuItem.Click
PDAM.show()
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
login.Show()
End Sub
End Class
Hasil program :
Public Class PDAM
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, 3)
If X = "TOK" Then
tipe.Text = "toko"
biaya.Text = 25000
harga.Text = 300
ElseIf X = "RUM" Then
tipe.Text = "rumah"
biaya.Text = 15000
harga.Text = 100
ElseIf X = "SWA" Then
tipe.Text = "swalayan"
biaya.Text = 10000
harga.Text = 200
ElseIf X = "PAB" Then
tipe.Text = "pabrik"
biaya.Text = 250000
harga.Text = 500
End If
X = Microsoft.VisualBasic.Mid(kode.Text, 5, 3)
If X = "MED" Then
daerah.Text = "medan"
ElseIf X = "BEL" Then
daerah.Text = "belawan"
ElseIf X = "TEM" Then
daerah.Text = "aksara"
ElseIf X = "MAR" Then
daerah.Text = "marendal"
ElseIf X = "BIN" Then
daerah.Text = "binjai"
ElseIf X = "PAK" Then
daerah.Text = "lubukpakam"
End If
no_urut.Text = Microsoft.VisualBasic.Right(kode.Text, 3)
End Sub
Sub AddJumlah()
For i = 1 To 100
jumlah.Items.Add(i)
Next
End Sub
Private Sub PDAM_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
kode.Items.Add("TOK-MED-100")
kode.Items.Add("TOK-BEL-101")
kode.Items.Add("TOK-TEM-102")
kode.Items.Add("TOK-MAR-103")
kode.Items.Add("TOK-BIN-104")
kode.Items.Add("TOK-PAK-105")
kode.Items.Add("RUM-MED-106")
kode.Items.Add("RUM-BEL-107")
kode.Items.Add("RUM-TEM-108")
kode.Items.Add("RUM-MAR-109")
kode.Items.Add("RUM-BIN-110")
kode.Items.Add("RUM-PAK-111")
kode.Items.Add("SWA-MED-112")
kode.Items.Add("SWA-BEL-113")
kode.Items.Add("SWA-TEM-114")
kode.Items.Add("SWA-MAR-115")
kode.Items.Add("SWA-BIN-116")
kode.Items.Add("SWA-PAK-117")
kode.Items.Add("PAB-MED-118")
kode.Items.Add("PAB-BEL-119")
kode.Items.Add("PAB-TEM-120")
kode.Items.Add("PAB-MAR-121")
kode.Items.Add("PAB-BIN-122")
kode.Items.Add("PAB-PAK-123")
AddJumlah()
RancangTabel()
End Sub
Private Sub total_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles total.Enter
total.Text = biaya.Text + harga.Text * jumlah.Text
End Sub
Private Sub pajak_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles pajak.Enter
pajak.Text = 0.1 * total.Text
End Sub
Private Sub pembayaran_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles pembayaran.Enter
pembayaran.Text = Val(total.Text) + Val(pajak.Text)
End Sub
Sub RancangTabel()
With LV
.Columns.Add("kode pelanggan", 80, HorizontalAlignment.Center)
.Columns.Add("daerah", 120, HorizontalAlignment.Left)
.Columns.Add("tipe pelanggan", 60, HorizontalAlignment.Center)
.Columns.Add("biaya beban", 80, HorizontalAlignment.Right)
.Columns.Add("harga", 100, HorizontalAlignment.Center)
.Columns.Add("jumlah pemakaian", 80, HorizontalAlignment.Center)
.Columns.Add("total tagihan", 80, HorizontalAlignment.Right)
.Columns.Add("pajak", 80, HorizontalAlignment.Right)
.Columns.Add("pembayaran", 80, HorizontalAlignment.Right)
.View = View.Details
.GridLines = True
.FullRowSelect = True
End With
End Sub
Sub MasukTabel()
Dim lst As New ListViewItem
lst.Text = kode.Text
lst.SubItems.Add(daerah.Text)
lst.SubItems.Add(tipe.Text)
lst.SubItems.Add(biaya.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jumlah.Text)
lst.SubItems.Add(total.Text)
lst.SubItems.Add(pembayaran.Text)
lst.SubItems.Add(pajak.Text)
LV.Items.Add(lst)
End Sub
Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
MasukTabel()
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 hps_baris_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hps_baris.Click
If LV.SelectedItems.Count <> 0 Then
LV.Items.Remove(LV.SelectedItems(0))
Else
MsgBox("Pilih terlebih dahulu baris data yang akan di hapus")
End If
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
End
End Sub
End Class
Hasil program:
untuk melihat soal : klik disini