Contoh Soal UAS Visual Basic Semester 3
: Buat Database TokoBuku
Buat Tabel Buku
Buat Tabel Pelanggan
Buat Tabel Transaksi
: Buat Database TokoBuku
Buat Tabel Buku
Field | Type | Panjang | Keterangan |
kdbuku | Teks | 5 | Primary key |
nmbuku | Teks | 30 | |
jmlbuku | Integer | ||
hrgbuku | currency |
Buat Tabel Pelanggan
Field | Type | Panjang | Keterangan |
Kdpelanggan | Teks | 5 | Primary key |
Nmpelanggan | Teks | 30 | |
Alamat | Teks | 50 | |
telp | teks | 30 |
Buat Tabel Transaksi
Field | Type | Panjang | Keterangan |
No_transaksi | Teks | 5 | |
Kd_buku | Teks | 5 | |
Kd_pelanggan | Teks | 5 | |
Jml_beli | interger | ||
Total_beli | currency |
Form Buku
listing
Dim i As Control
Private Sub batal_Click()
p = MsgBox("klik ok untuk membatalkan record", vbQuestion + vbOKCancel, "konfirmasi")
If p = vbOK Then
kosong
nonaktif
End If
simpan.Enabled = False
tambah.Enabled = True
End Sub
Private Sub Form_Load()
simpan.Enabled = False
nonaktif
End Sub
Sub aktif()
kode.Enabled = True
nama.Enabled = True
jumlah.Enabled = True
harga.Enabled = True
tambah.Enabled = True
keluar.Enabled = True
batal.Enabled = True
End Sub
Sub nonaktif()
kode.Enabled = False
nama.Enabled = False
jumlah.Enabled = False
harga.Enabled = False
simpan.Enabled = True
tambah.Enabled = True
End Sub
Sub kosong()
kode.Text = ""
nama.Text = ""
jumlah.Text = ""
harga.Text = ""
End Sub
Private Sub keluar_Click()
MsgBox "yakin anda ingin keluar...?"
End
End Sub
Private Sub last_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub next_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
MsgBox "data sudah di akhir record", "info"
Data1.Recordset.MoveLast
End If
End Sub
Private Sub pre_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "data sudah di awal record", "info"
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub simpan_Click()
On Error Resume Next
With Data1.Recordset
.AddNew
!kode_buku = kode.Text
!nama_buku = nama.Text
!jumlah_buku = jumlah.Text
!harga_buku = harga.Text
.Update
.MoveLast
nonaktif
On Error GoTo 0
tambah.Enabled = True
simpan.Enabled = False
End With
End Sub
Private Sub tambah_Click()
kosong
aktif
kode.SetFocus
tambah.Enabled = False
simpan.Enabled = True
End Sub
Private Sub top_Click()
Data1.Recordset.MoveFirst
End Sub
Dim i As Control
Private Sub batal_Click()
p = MsgBox("klik ok untuk membatalkan record", vbQuestion + vbOKCancel, "konfirmasi")
If p = vbOK Then
kosong
nonaktif
End If
simpan.Enabled = False
tambah.Enabled = True
End Sub
Private Sub Form_Load()
simpan.Enabled = False
nonaktif
End Sub
Sub aktif()
kode.Enabled = True
nama.Enabled = True
jumlah.Enabled = True
harga.Enabled = True
tambah.Enabled = True
keluar.Enabled = True
batal.Enabled = True
End Sub
Sub nonaktif()
kode.Enabled = False
nama.Enabled = False
jumlah.Enabled = False
harga.Enabled = False
simpan.Enabled = True
tambah.Enabled = True
End Sub
Sub kosong()
kode.Text = ""
nama.Text = ""
jumlah.Text = ""
harga.Text = ""
End Sub
Private Sub keluar_Click()
MsgBox "yakin anda ingin keluar...?"
End
End Sub
Private Sub last_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub next_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
MsgBox "data sudah di akhir record", "info"
Data1.Recordset.MoveLast
End If
End Sub
Private Sub pre_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "data sudah di awal record", "info"
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub simpan_Click()
On Error Resume Next
With Data1.Recordset
.AddNew
!kode_buku = kode.Text
!nama_buku = nama.Text
!jumlah_buku = jumlah.Text
!harga_buku = harga.Text
.Update
.MoveLast
nonaktif
On Error GoTo 0
tambah.Enabled = True
simpan.Enabled = False
End With
End Sub
Private Sub tambah_Click()
kosong
aktif
kode.SetFocus
tambah.Enabled = False
simpan.Enabled = True
End Sub
Private Sub top_Click()
Data1.Recordset.MoveFirst
End Sub
Form Pelanggan
Listing
Dim i As Control
Private Sub cmdbatal_Click()
p = MsgBox("Klik ok untuk membatalkan record", vbQuestion + vbOKCancel, "Konfirmasi")
If p = vbOK Then
kosong
nonaktif
End If
cmdsimpan.Enabled = False
cmdtambah.Enabled = True
End Sub
Private Sub cmdkeluar_Click()
MsgBox "Yakin anda ingin keluar...?"
End
End Sub
Private Sub cmdlast_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub cmdnext_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
MsgBox "Data sudah diakhir record", "info"
Data1.Recordset.MoveLast
End If
End Sub
Private Sub cmdprevious_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "Data sudah di awal record ", "info"
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub cmdsimpan_Click()
On Error Resume Next
With Data1.Recordset
.AddNew
!kdbuku = txtkd.Text
!nmbuku = txtnm.Text
!jmlbuku = txtjml.Text
!hrgbuku = txthrg.Text
.Update
.MoveLast
nonaktif
On Error GoTo 0
cmdtambah.Enabled = True
cmdsimpan.Enabled = False
End With
End Sub
Private Sub cmdtambah_Click()
kosong
aktif
txtkd.SetFocus
cmdtambah.Enabled = False
cmdsimpan.Enabled = True
End Sub
Private Sub cmdtop_Click()
Data1.Recordset.MoveFirst
End Sub
Private Sub Form_Load()
cmdsimpan.Enabled = False
nonaktif
End Sub
Sub aktif()
txtkd.Enabled = True
txtnm.Enabled = True
txtjml.Enabled = True
txthrg.Enabled = True
cmdtambah.Enabled = True
cmdkeluar.Enabled = True
cmdbatal.Enabled = True
End Sub
Sub nonaktif()
txtkd.Enabled = False
txtnm.Enabled = False
txtjml.Enabled = False
txthrg.Enabled = False
cmdsimpan.Enabled = True
cmdtambah.Enabled = True
End Sub
Sub kosong()
txtkd.Text = ""
txtnm.Text = ""
txtjml.Text = ""
txthrg.Text = ""
End Sub
Dim i As Control
Private Sub cmdbatal_Click()
p = MsgBox("Klik ok untuk membatalkan record", vbQuestion + vbOKCancel, "Konfirmasi")
If p = vbOK Then
kosong
nonaktif
End If
cmdsimpan.Enabled = False
cmdtambah.Enabled = True
End Sub
Private Sub cmdkeluar_Click()
MsgBox "Yakin anda ingin keluar...?"
End
End Sub
Private Sub cmdlast_Click()
Data1.Recordset.MoveLast
End Sub
Private Sub cmdnext_Click()
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
MsgBox "Data sudah diakhir record", "info"
Data1.Recordset.MoveLast
End If
End Sub
Private Sub cmdprevious_Click()
Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then
MsgBox "Data sudah di awal record ", "info"
Data1.Recordset.MoveFirst
End If
End Sub
Private Sub cmdsimpan_Click()
On Error Resume Next
With Data1.Recordset
.AddNew
!kdbuku = txtkd.Text
!nmbuku = txtnm.Text
!jmlbuku = txtjml.Text
!hrgbuku = txthrg.Text
.Update
.MoveLast
nonaktif
On Error GoTo 0
cmdtambah.Enabled = True
cmdsimpan.Enabled = False
End With
End Sub
Private Sub cmdtambah_Click()
kosong
aktif
txtkd.SetFocus
cmdtambah.Enabled = False
cmdsimpan.Enabled = True
End Sub
Private Sub cmdtop_Click()
Data1.Recordset.MoveFirst
End Sub
Private Sub Form_Load()
cmdsimpan.Enabled = False
nonaktif
End Sub
Sub aktif()
txtkd.Enabled = True
txtnm.Enabled = True
txtjml.Enabled = True
txthrg.Enabled = True
cmdtambah.Enabled = True
cmdkeluar.Enabled = True
cmdbatal.Enabled = True
End Sub
Sub nonaktif()
txtkd.Enabled = False
txtnm.Enabled = False
txtjml.Enabled = False
txthrg.Enabled = False
cmdsimpan.Enabled = True
cmdtambah.Enabled = True
End Sub
Sub kosong()
txtkd.Text = ""
txtnm.Text = ""
txtjml.Text = ""
txthrg.Text = ""
End Sub
Form Transaksi
Listing
Dim i As Control
Sub nonaktif()
TRANSAKSI.Enabled = False
kodeb.Enabled = False
NAMAB.Enabled = False
HARGA.Enabled = False
JUMLAH.Enabled = False
TOTAL.Enabled = False
kodep.Enabled = False
namap.Enabled = False
alamat.Enabled = False
BAYAR.Enabled = False
KEMBALI.Enabled = False
ADD.Enabled = True
SAVE.Enabled = False
CANCEL.Enabled = False
End Sub
Sub aktif()
TRANSAKSI.Enabled = True
kodeb.Enabled = True
JUMLAH.Enabled = True
kodep.Enabled = True
BAYAR.Enabled = True
ADD.Enabled = False
SAVE.Enabled = True
CANCEL.Enabled = True
End Sub
Sub clear()
TRANSAKSI.Text = ""
kodeb.Text = "Pilihan"
NAMAB.Text = ""
HARGA.Text = ""
JUMLAH.Text = ""
TOTAL.Text = ""
kodep.Text = "Pilihan"
namap.Text = ""
alamat.Text = ""
BAYAR.Text = ""
KEMBALI.Text = ""
End Sub
Private Sub ADD_Click()
clear
aktif
TRANSAKSI.SetFocus
End Sub
Private Sub BAYAR_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KEMBALI = Val(BAYAR.Text) - Val(TOTAL.Text)
End If
End Sub
Private Sub CANCEL_Click()
p = MsgBox("Klik OK untuk membatalkan penginputan record", vbQuestion + vbOKCancel, "Konfirmasi")
If p = vbOK Then
clear
nonaktif
End If
End Sub
Private Sub CLOSE_Click()
q = MsgBox("Anda yakin ingin keluar?", vbYesNo, "Info")
If q = vbYes Then
End
End If
End Sub
Private Sub Form_Load()
kodep.AddItem "1"
kodep.AddItem "2"
kodeb.AddItem "a"
kodeb.AddItem "b"
nonaktif
End Sub
Private Sub JUMLAH_Change()
TOTAL = Val(HARGA.Text) * Val(JUMLAH.Text)
End Sub
Private Sub kodeb_Click()
If kodeb.Text = "a" Then
NAMAB.Text = "laptop"
HARGA.Text = 5000000
Else
NAMAB.Text = "hand phone"
HARGA.Text = 2500000
End If
End Sub
Private Sub kodep_Click()
If kodep.Text = "1" Then
namap.Text = "TWP"
alamat.Text = "Werekes"
Else
namap.Text = "PPH'"
alamat.Text = "Warakas"
End If
End Sub
Private Sub SAVE_Click()
On Error Resume Next
With Data_Transaksi.Recordset
.AddNew
!No_Transaksi = TRANSAKSI.Text
!Kode_Barang = kodeb.Text
!Kode_Pelanggan = kodep.Text
!Jumlah_Beli = JUMLAH.Text
!Total_Beli = TOTAL.Text
!Uang_Bayar = BAYAR.Text
!Uang_Kembali = KEMBALI.Text
.Update
.MoveLast
nonaktif
On Error GoTo 0
End With
End Sub
Sub nonaktif()
TRANSAKSI.Enabled = False
kodeb.Enabled = False
NAMAB.Enabled = False
HARGA.Enabled = False
JUMLAH.Enabled = False
TOTAL.Enabled = False
kodep.Enabled = False
namap.Enabled = False
alamat.Enabled = False
BAYAR.Enabled = False
KEMBALI.Enabled = False
ADD.Enabled = True
SAVE.Enabled = False
CANCEL.Enabled = False
End Sub
Sub aktif()
TRANSAKSI.Enabled = True
kodeb.Enabled = True
JUMLAH.Enabled = True
kodep.Enabled = True
BAYAR.Enabled = True
ADD.Enabled = False
SAVE.Enabled = True
CANCEL.Enabled = True
End Sub
Sub clear()
TRANSAKSI.Text = ""
kodeb.Text = "Pilihan"
NAMAB.Text = ""
HARGA.Text = ""
JUMLAH.Text = ""
TOTAL.Text = ""
kodep.Text = "Pilihan"
namap.Text = ""
alamat.Text = ""
BAYAR.Text = ""
KEMBALI.Text = ""
End Sub
Private Sub ADD_Click()
clear
aktif
TRANSAKSI.SetFocus
End Sub
Private Sub BAYAR_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
KEMBALI = Val(BAYAR.Text) - Val(TOTAL.Text)
End If
End Sub
Private Sub CANCEL_Click()
p = MsgBox("Klik OK untuk membatalkan penginputan record", vbQuestion + vbOKCancel, "Konfirmasi")
If p = vbOK Then
clear
nonaktif
End If
End Sub
Private Sub CLOSE_Click()
q = MsgBox("Anda yakin ingin keluar?", vbYesNo, "Info")
If q = vbYes Then
End
End If
End Sub
Private Sub Form_Load()
kodep.AddItem "1"
kodep.AddItem "2"
kodeb.AddItem "a"
kodeb.AddItem "b"
nonaktif
End Sub
Private Sub JUMLAH_Change()
TOTAL = Val(HARGA.Text) * Val(JUMLAH.Text)
End Sub
Private Sub kodeb_Click()
If kodeb.Text = "a" Then
NAMAB.Text = "laptop"
HARGA.Text = 5000000
Else
NAMAB.Text = "hand phone"
HARGA.Text = 2500000
End If
End Sub
Private Sub kodep_Click()
If kodep.Text = "1" Then
namap.Text = "TWP"
alamat.Text = "Werekes"
Else
namap.Text = "PPH'"
alamat.Text = "Warakas"
End If
End Sub
Private Sub SAVE_Click()
On Error Resume Next
With Data_Transaksi.Recordset
.AddNew
!No_Transaksi = TRANSAKSI.Text
!Kode_Barang = kodeb.Text
!Kode_Pelanggan = kodep.Text
!Jumlah_Beli = JUMLAH.Text
!Total_Beli = TOTAL.Text
!Uang_Bayar = BAYAR.Text
!Uang_Kembali = KEMBALI.Text
.Update
.MoveLast
nonaktif
On Error GoTo 0
End With
End Sub
Post a Comment