Materi Visual Basic II Pra UTS
-
Upload
helmy-surachman -
Category
Documents
-
view
82 -
download
11
Transcript of Materi Visual Basic II Pra UTS
VB II PERTEMUAN PRA UTS
1
Field name Data Type Field Size FormatNofak Text 10Kobar Text 5Nabar Text 20Hjual Currency CurrencyQty Number Long integerSubtotal Currency Currency
Cara Membuka Microsoft AccessStart All Program Microsoft Office Ms. Access
Membuat DatabaseFile New Blank database simpan dengan nama: penjualan.mdb (format access2002-2003)
Membuat tabel1. Barang
Field name Data Type Field Size FormatKobar Text 5 PkNabar Text 20Hbeli Currency CurrencyHjual Currency CurrencyStok Number Long integer
Isi data barang sebanyak 5 record2. Pengguna
Field name Data Type Field Size FormatUserid Text 5 PkNmuser Text 20Password Text 10Akses Text 15
Isi data pengguna sebanyak 5 record dan akses = admin.3. Faktur
Field name Data Type Field Size FormatNofak Text 10 PkTglfak Date/timeUserid Text 20Total Currency Currency
4. DetailfakField name Data Type Field Size FormatNofak Text 10Qty Number Long integerSubtotal Currency CurrencyKobar Text 5
5. Tmpjual
2
VB II PERTEMUAN PRA UTS
Membuat Relationship
Mengaktifkan VBStart All Program Microsoft Visual Studio 6.0 Microsoft Visual basic 6.0
Membuat ProjectFile New project simpan dengan nama: penjualan.pjx
Design Form Barang
3
VB II PERTEMUAN PRA UTS
Menambahkan KomponenKomponen yang ditambahkan:
1. Tab2. Adodc3. MSHFleshGrid4. Cristal Report
Cara: Tekan CTRL + T atau klik kanan pada components sehingga muncul kotak dialog components
4
VB II PERTEMUAN PRA UTS
Pengkoneksian1. Koneksi Adodc
a. Pada jendela properties pilih ConnectionStringb. Maka akan tampil jendela PropertyPages sbb.
c. Pilih use connection string Build Microsoft Jet 4.0 OLE DB Provider Next
5
VB II PERTEMUAN PRA UTS
d. Tampil jendela data link properties
e. Pada select or enter a database name klik ... (ke folder database penjualan.mdb yang telah dibuat sebelumnya open)
f. Klik Test Connection Ok Okg. Setelah itu pada jendela Properties pilih RecordSourceh. Tampil jendela Property pages
2. Koneksi MSHFlexGrid
Pada jendela Properties pilih Datasource :Adodc1
6
VB II PERTEMUAN PRA UTS
Listing program Form barang
Dim isibrg As Boolean
Sub tabel()Grid1.Cols = 6Grid1.Rows = 10Grid1.ColWidth(0) = 200Grid1.ColWidth(1) = 500Grid1.ColWidth(2) = 2000Grid1.ColWidth(3) = 1500Grid1.ColWidth(4) = 1500Grid1.ColWidth(5) = 500Grid1.ColAlignment(1) = 3End Sub
Sub awal()Adojual.RecordSource = "select * from barang" Adojual.Refreshtkobar.Enabled = False tnabar.Enabled = False thbeli.Enabled = False thjual.Enabled = False tstok.Enabled = False End Sub
Sub bersih() tkobar = "" tnabar = "" thbeli = "" thjual = "" tstok = "" End SubSub aktif() tkobar.Enabled = True tnabar.Enabled = True thbeli.Enabled = True thjual.Enabled = True tstok.Enabled = True End Sub
Sub tampil()tkobar.Text = Adojual.Recordset.Fields("kobar")tnabar.Text = Adojual.Recordset.Fields("nabar")
7
VB II PERTEMUAN PRA UTS
thbeli.Text = Adojual.Recordset.Fields("hbeli") thjual.Text = Adojual.Recordset.Fields("hjual") tstok.Text = Adojual.Recordset.Fields("stok") End Sub
Private Sub Form_Activate()awal tampilisibrg = TrueEnd Sub
Private Sub cmdadd_Click()aktif bersih tkobar.SetFocus End Sub
Private Sub cmdsave_Click()With Adojual.Recordset
If isibrg = True Then.AddNew.Fields("kobar") = tkobar.Fields("nabar") = tnabar.Fields("hbeli") = Val(thbeli).Fields("hjual") = Val(thjual).Fields("stok") = Val(tstok).UpdateElse.Fields("kobar") = tkobar.Fields("nabar") = tnabar.Fields("hbeli") = Val(thbeli).Fields("hjual") = Val(thjual).Fields("stok") = Val(tstok).UpdateEnd IfEnd WithAdojual.RecordSource = "select * from barang" Adojual.RefreshOn Error GoTo 0 cmdcancel_Click
End Sub
Private Sub cmdcancel_Click()awal
8
VB II PERTEMUAN PRA UTS
End Sub
Private Sub cmddel_Click()If Len(Trim(tkobar.Text)) = "" ThenExit SubEnd Ifp = MsgBox("Benar mau dihapus?", 32 + 4, "Tanya") If p = vbYes ThenAdojual.Recordset.DeleteAdojual.Refresh bersihawal Else awal End IfEnd Sub
Private Sub cmdedit_Click()isibrg = False aktiftkobar.Enabled = False tnabar.SetFocusEnd Sub
Private Sub cmdtop_Click() Adojual.Recordset.MoveFirst tampilEnd Sub
Private Sub cmdlast_Click() Adojual.Recordset.MoveLast tampilEnd Sub
Private Sub cmdnext_Click()Adojual.Recordset.MoveNextIf Adojual.Recordset.EOF Then
MsgBox "Data sudah diakhir record", 48, "Info" Adojual.Recordset.MoveLast
End If tampil End Sub
Private Sub cmdprev_Click()Adojual.Recordset.MovePrevious
9
VB II PERTEMUAN PRA UTS
If Adojual.Recordset.BOF ThenMsgBox "Data sudah di awal record", 48, "Info" Adojual.Recordset.MoveFirst
End IftampilEnd Sub
Private Sub SSTab1_DblClick()Adojual.RefreshEnd Sub
Private Sub cmdcari_Click()Adojual.RecordSource = "select * from barang where kobar = '" & tckobar & "'" Adojual.RefreshWith Adojual.Recordset
If .PageCount <> 0 Then Adojual.Refresh tckobar = "" tckobar.SetFocusCall tampil
ElseMsgBox "Kode " + tckobar + " tidak ada", 34, "Info" tckobar = ""tckobar.SetFocusAdojual.RecordSource = "select * from barang" Adojual.RefreshEnd IfEnd With
End Sub
Private Sub tcnabar_Change()Adojual.RecordSource = "select * from barang where nabar like '%" & tcnabar & "%'" Adojual.RefreshEnd Sub
Private Sub cmdclose_Click()t = MsgBox("Anda yakin mau menutup form ini?", 36, "Tanya") If t = vbYes ThenUnload MeEnd IfEnd Sub
10
VB II PERTEMUAN PRA UTS
Design Form Transaksi
Komponen yang ditambahkan:5 buah Adodc, pada jendela properties lakukan koneksi untuk ConnectionStringdan RecordSource : Data barang ketikkan di command text (SQL) :select * from barang Data pengguna ketikkan di command text (SQL) :select * from pengguna Data faktur ketikkan di command text (SQL) :select * from faktur Data detail ketikkan di command text (SQL) :select * from detailfak Data temporary ketikkan di command text (SQL) :select * from tmpjual
1 buah MSHFlexGrid, pada jendela properties Datasource :dttmpjual
1 buah Data Combo (Microsoft Data List Control 6.0 (OLEDB)), pada jendelaproperties Rowsource: dtbarang , ListField: kobar
11
VB II PERTEMUAN PRA UTS
Listing Program Form Transaksi
Sub hapusgrid()If dttmpjual.Recordset.RecordCount <= 0 ThenExit Sub End If dttmpjual.Recordset.MoveFirstDo While Not dttmpjual.Recordset.EOF dttmpjual.Recordset.Delete dttmpjual.Recordset.MoveNextLoop dttmpjual.Refresh End Sub
Private Sub Form_Activate()hapusgriddttmpjual.RecordSource = "select * from tmpjual" dttmpjual.Refreshnonttglfak.Text = Datetuserid.Text = Form3.tuser.Text tnmuser.Text = Form3.tnmuser.Text End Sub
Private Sub Timer1_Timer()Text11.Text = Time() End Sub
Sub no()Dim urutan As StringDim hitung As Longdtfaktur.RecordSource = "select * from faktur" dtfaktur.RefreshIf dtfaktur.Recordset.RecordCount <= 0 Then urutan = dtfaktur.Recordset.RecordCount + 1
Sub non() tnofak.Enabled = False ttglfak.Enabled = False tuserid.Enabled = False tnmuser.Enabled = False ckobar.Enabled = False tnabar.Enabled = False thjual.Enabled = False tstok.Enabled = False tqty.Enabled = False tsubtotal.Enabled = False ttotal.Enabled = False tubay.Enabled = False tukem.Enabled = False End Sub
Sub aktif() ckobar.Enabled = True tqty.Enabled = True tubay.Enabled = True End Sub
Sub bersih() tnofak = "" ckobar = "" tnabar = "" thjual = "" tstok = "" tqty = ""tsubtotal = "" ttotal = "" tubay = "" tukem = "" End Sub
tnofak.Text = "F" + Format(Date, "yymm") + Format(urutan, "000") Elsedtfaktur.Recordset.MoveLasturutan = Val(Right(dtfaktur.Recordset!nofak, 3)) + 1tnofak.Text = "F" + Format(Date, "yymm") + Format(urutan, "000") End IfEnd Sub
Private Sub cmdadd_Click()aktif noEnd SubPrivate Sub ckobar_Change()dtbarang.RecordSource = "select * from barang where kobar='" & ckobar & "'" dtbarang.Recordset.MoveFirstDo While Not dtbarang.Recordset.EOFIf ckobar.Text = dtbarang.Recordset!kobar ThenWith dtbarang.Recordset tnabar.Text = !nabar thjual.Text = !hjual tstok.Text = !stokExit Sub End With End Ifdtbarang.Recordset.MoveNext tqty.SetFocus
LoopEnd Sub
Private Sub tqty_KeyPress(KeyAscii As Integer)If KeyAscii = 13 Then
dttmpjual.RecordSource = "select * from tmpjual" dttmpjual.Refreshdtbarang.RecordSource = "select * from barang" dtbarang.Refresh
tsubtotal = Val(thjual.Text) * Val(tqty.Text) dttmpjual.RecordSource = "select * from tmpjual" dttmpjual.Refresh
a = MsgBox("Mau tambah data lagi?", 32 + 4, "lagi") If a = vbYes Then
With dttmpjual.Recordset.AddNew.Fields("nofak") = tnofak.Text.Fields("kobar") = ckobar.Text.Fields("nabar") = tnabar.Text.Fields("hjual") = thjual.Text.Fields("qty") = Val(tqty.Text).Fields("subtotal") = Val(tsubtotal.Text).UpdateEnd Withdttmpjual.RecordSource = "select * from tmpjual" dttmpjual.Refreshdtbarang.Recordset.Fields("stok") = Val(tstok.Text) - Val(tqty.Text)
ttotal.Text = Val(ttotal.Text) + Val(tsubtotal.Text)dtbarang.Recordset.Update ckobar = ""tnabar = ""thjual = "" tstok = "" tqty = ""tsubtotal = ""
ckobar.SetFocus ElseWith dttmpjual.Recordset
.AddNew
.Fields("nofak") = tnofak.Text
.Fields("kobar") = ckobar.Text
.Fields("nabar") = tnabar.Text
.Fields("hjual") = thjual.Text
.Fields("qty") = Val(tqty.Text)
.Fields("subtotal") = Val(tsubtotal.Text)
.UpdateEnd Withdttmpjual.RecordSource = "select * from tmpjual" dttmpjual.Refreshdtbarang.Recordset.Fields("stok") = Val(tstok.Text) - Val(tqty.Text) ttotal.Text = Val(ttotal.Text) + Val(tsubtotal.Text) dtbarang.Recordset.Updateckobar = "" tnabar = "" thjual = "" tstok = "" tqty = ""tsubtotal = ""
nontubay.Enabled = True
tubay.SetFocusEnd Ifdttmpjual.RecordSource = "select * from tmpjual" dttmpjual.RefreshEnd If
End Sub
Private Sub tubay_Change() tukem = Val(tubay) - Val(ttotal) End Sub
Private Sub cmdsave_Click() dtfaktur.RecordSource = "select * from faktur" dtfaktur.Refreshdttmpjual.RecordSource = "select *from tmpjual"dttmpjual.Refreshdtdetail.RecordSource = "select * from detailfak" dtdetail.RefreshWith dtfaktur.Recordset
.AddNew
.Fields("nofak") = tnofak.Text
.Fields("tglfak") = ttglfak.Text
.Fields("userid") = tuserid.Text
.Fields("total") = ttotal.Text
.Update End With dttmpjual.Recordset.MoveFirst n = 1While Not dttmpjual.Recordset.EOF
dtdetail.Recordset.AddNewdtdetail.Recordset.Fields("nofak") = dttmpjual.Recordset.Fields("nofak") dtdetail.Recordset.Fields("kobar") = dttmpjual.Recordset.Fields("kobar") dtdetail.Recordset.Fields("qty") = dttmpjual.Recordset.Fields("qty") dtdetail.Recordset.Fields("subtotal") = dttmpjual.Recordset.Fields("subtotal") dtdetail.Recordset.Updatedttmpjual.Recordset.MoveNext
n = n + 1Wend bersih hapusgriddttmpjual.RecordSource = "select *from tmpjual" dttmpjual.RefreshnonEnd Sub
Private Sub cmdcancel_Click()If tstok <> "" Thendtbarang.Recordset.Fields("stok") = dtbarang.Recordset.Fields("stok") + Val(tstok.Text)dtbarang.Recordset.UpdateEnd If bersih nonhapusgriddttmpjual.RecordSource = "select * from tmpjual" dttmpjual.RefreshEnd Sub
Private Sub cmdclose_Click()If tstok <> "" Thendtbarang.Recordset.Fields("stok") = dtbarang.Recordset.Fields("stok") + Val(tstok.Text)dtbarang.Recordset.UpdateEnd Ifdttmpjual.RecordSource = "select * from tmpjual" dttmpjual.RefreshUnload MeEnd Sub
Design Form Login
Listing Program Form Login
Private Sub cmdlogin_Click()Adologin.RecordSource = "select password from pengguna" Adologin.RefreshWith Adologin.Recordset
.Find ("password = '" & Trim(tpwd) & "'") If .EOF ThenMsgBox " Password anda salah", vbCritical + vbYesNo, "Info" tpwd = ""tpwd.SetFocusElse
Form2.Show Form3.Hide End IfEnd With
End Sub
Private Sub tuser_KeyPress(KeyAscii As Integer)If KeyAscii = 13 ThenAdologin.RecordSource = "select userid,nmuser from pengguna" Adologin.RefreshAdologin.Recordset.Find ("userid = '" & Trim(tuser) & "'") If Adologin.Recordset.EOF ThenMsgBox " User ID anda salah", vbCritical + vbYesNo, "Info" tuser = ""tuser.SetFocusElsetnmuser.Text = Adologin.Recordset.Fields("nmuser")tnmuser.Enabled = False tpwd.SetFocusEnd If End If End Sub
Private Sub cmdclose_Click()t = MsgBox("Anda yakin mau menutup form ini?", 36, "Tanya") If t = vbYes ThenUnload MeEnd IfEnd Sub
MEMBUAT LAPORAN DENGAN CRYSTAL REPORT
Start All Program Crystal Report Tools Crystal ReportMaka akan tampil Jendela :
Pilih Choose an Expert :Standart OK
Tampil Jendela Standart report Expert, klik Database muncul jendela Data explorer, klik Find Database File ADD
Lalu ke “C:\LAB O MALAM\NIM\penjualan.mdb”. Hasil:
Lalu Klik ADD. Hasil: lalu Klik Close.
Hasil:
Klik Next>> Klik ADD ALL. Hasil:
20
Lalu Klik Finish Klik tab Design. Hasil:
Tambahkan Judul Laporan dan Percantik design laporan barangSave dengan nama :reportbarangHasil:
Start all Program Microsoft Visual Studia 6.0 Microsoft Visual basic 6.0. File Open Project Buka Project penjualan.vbpTekan CTRL+T sehingga muncul kotak dialog Component seperti dibawah ini:
21
Di Properties Form barang, lakukan beberapa settingan sbb.
C:\LABO MALAM\NIM\reportbarang Lalu Klik OK
Listing Untuk Command cetak
22
MEMBUAT MENU UTAMA
1. Aktifkan Microsoft Visual Basic 6.02. Buka Project penjualan.vbp3. Buka Form baru untuk menu utama
4. Pada menu bar pilih:
5. Akan tampil jendela sbb:
6. Design Menu Utama sbb:
23
7. Hasil sbb:
8. Listing Program:
9. Design lah Form Menu Utama sehingga terlihat lebih cantik.