Setelah kita melihat contoh aplikasi kegiatan penerimaan siswa gres sekolah mengemudi memakai visual basic 6.0, selanjutnya kita akan menciptakan form data mobil.
Pertama-tama buat terlebih dahulu formnya ibarat dibawah ini, juga beri name masing-masing :
Catatan :
A. tambahkan crystal report dan beri name "cr"
B. Tambahkan tabel grid dan beri name "grid"
1.Klik pada cbtambah dan pastekan koding berikut :
Call koneksi
Call bersih
Call aktif
rsdatamobil.Open "select*from tmobil order by kodemobil desc", KON
With rsdatamobil
If .BOF And .EOF Then
tkodemobil.Text = "KM" + "01"
Else
tkodemobil.Text = "KM" + Right(Str(Val(Right(.Fields("kodemobil"), 2)) + 101), 2)
End If
End With
tkodemobil.Enabled = False
tmerk.SetFocus
cbbatal.Enabled = True
cbsunting.Enabled = False
cbperbarui.Enabled = False
cbhapus.Enabled = False
Call tampil
cbtambah.Enabled = False
notengah.Enabled = False
nobelakang.Enabled = False
Call bersih
Call aktif
rsdatamobil.Open "select*from tmobil order by kodemobil desc", KON
With rsdatamobil
If .BOF And .EOF Then
tkodemobil.Text = "KM" + "01"
Else
tkodemobil.Text = "KM" + Right(Str(Val(Right(.Fields("kodemobil"), 2)) + 101), 2)
End If
End With
tkodemobil.Enabled = False
tmerk.SetFocus
cbbatal.Enabled = True
cbsunting.Enabled = False
cbperbarui.Enabled = False
cbhapus.Enabled = False
Call tampil
cbtambah.Enabled = False
notengah.Enabled = False
nobelakang.Enabled = False
2.Klik pada cbsimpan dan pastekan koding berikut :
If tkodemobil.Text = "" Or tmerk.Text = "" Or ttipe.Text = "" Or notengah.Text = "" Or nobelakang.Text = "" Then
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tmerk.Text) < 3 Then
MsgBox "Merk Mobil harus lebih dari 2 karakter", vbCritical
tmerk.SetFocus
ElseIf Len(ttipe.Text) < 3 Then
MsgBox "Tipe Mobil harus lebih dari 2 karakter", vbCritical
ttipe.SetFocus
Else
Call koneksi
rsdatamobil.Open "insert into tmobil values('" & tkodemobil & "','" & tmerk & "','" & ttipe & "','" & tplat & "')", KON
MsgBox "Data Sudah Tersimpan", vbInformation
Call tampil
Call bersih
Call nonaktif
cbtambah.Enabled = True
End If
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tmerk.Text) < 3 Then
MsgBox "Merk Mobil harus lebih dari 2 karakter", vbCritical
tmerk.SetFocus
ElseIf Len(ttipe.Text) < 3 Then
MsgBox "Tipe Mobil harus lebih dari 2 karakter", vbCritical
ttipe.SetFocus
Else
Call koneksi
rsdatamobil.Open "insert into tmobil values('" & tkodemobil & "','" & tmerk & "','" & ttipe & "','" & tplat & "')", KON
MsgBox "Data Sudah Tersimpan", vbInformation
Call tampil
Call bersih
Call nonaktif
cbtambah.Enabled = True
End If
3.Klik pada cbsunting dan pastekan koding berikut :
Call koneksi
rsdatamobil.Open "select*from tmobil where kodemobil='" & tcari.Text & "'", KON
If rsdatamobil.EOF Then
MsgBox "Data Tidak Ditemukan", vbCritical
Call bersih
tcari.SetFocus
Else
With rsdatamobil
tkodemobil.Text = .Fields("kodemobil")
tmerk.Text = .Fields("merkmobil")
ttipe.Text = .Fields("tipemobil")
tplat.Text = .Fields("platnomor")
End With
Call aktif
tkodemobil.Enabled = False
cbtambah.Enabled = False
tplat.Enabled = False
cbsimpan.Enabled = False
cbhapus.Enabled = False
cbsunting.Enabled = False
End If
rsdatamobil.Open "select*from tmobil where kodemobil='" & tcari.Text & "'", KON
If rsdatamobil.EOF Then
MsgBox "Data Tidak Ditemukan", vbCritical
Call bersih
tcari.SetFocus
Else
With rsdatamobil
tkodemobil.Text = .Fields("kodemobil")
tmerk.Text = .Fields("merkmobil")
ttipe.Text = .Fields("tipemobil")
tplat.Text = .Fields("platnomor")
End With
Call aktif
tkodemobil.Enabled = False
cbtambah.Enabled = False
tplat.Enabled = False
cbsimpan.Enabled = False
cbhapus.Enabled = False
cbsunting.Enabled = False
End If
4.Klik pada cbperbarui dan pastekan koding berikut :
If tkodemobil.Text = "" Or tmerk.Text = "" Or ttipe.Text = "" Or tplat.Text = "" Then
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tmerk.Text) < 3 Then
MsgBox "Merk Mobil harus lebih dari 2 karakter", vbCritical
tmerk.SetFocus
ElseIf Len(ttipe.Text) < 3 Then
MsgBox "Tipe Mobil harus lebih dari 2 karakter", vbCritical
ttipe.SetFocus
Else
Call koneksi
rsdatamobil.Open "update tmobil set merkmobil='" & tmerk & "',tipemobil='" & ttipe & "',platnomor='" & tplat & "' where kodemobil='" & tkodemobil.Text & "'", KON
MsgBox "Data Berhasil di Update", vbInformation, "Info"
bersih
Call tampil
Call nonaktif
cbtambah.Enabled = True
End If
MsgBox "Data Belum terisi semua", vbCritical
ElseIf Len(tmerk.Text) < 3 Then
MsgBox "Merk Mobil harus lebih dari 2 karakter", vbCritical
tmerk.SetFocus
ElseIf Len(ttipe.Text) < 3 Then
MsgBox "Tipe Mobil harus lebih dari 2 karakter", vbCritical
ttipe.SetFocus
Else
Call koneksi
rsdatamobil.Open "update tmobil set merkmobil='" & tmerk & "',tipemobil='" & ttipe & "',platnomor='" & tplat & "' where kodemobil='" & tkodemobil.Text & "'", KON
MsgBox "Data Berhasil di Update", vbInformation, "Info"
bersih
Call tampil
Call nonaktif
cbtambah.Enabled = True
End If
5.Klik pada cbhapus dan pastekan koding berikut :
Call koneksi
a = MsgBox("Yakin Ingin Hapus Data ini?", vbQuestion + vbYesNo, "tanya")
If a = vbYes Then
rsdatamobil.Open "delete from tmobil where kodemobil='" & tcari.Text & "'", KON
MsgBox "Data telah terhapus", vbInformation
bersih
tcari.Text = ""
Call nonaktif
cbtambah.Enabled = True
End If
Call tampil
a = MsgBox("Yakin Ingin Hapus Data ini?", vbQuestion + vbYesNo, "tanya")
If a = vbYes Then
rsdatamobil.Open "delete from tmobil where kodemobil='" & tcari.Text & "'", KON
MsgBox "Data telah terhapus", vbInformation
bersih
tcari.Text = ""
Call nonaktif
cbtambah.Enabled = True
End If
Call tampil
6.Klik pada cbbatal dan pastekan koding berikut :
Call bersih
Call nonaktif
cbtambah.Enabled = True
Call nonaktif
cbtambah.Enabled = True
7.Klik pada cbcari dan pastekan koding berikut :
Call koneksi
rsdatamobil.Open "select*from tmobil where kodemobil='" & tcari.Text & "'", KON
If rsdatamobil.EOF Then
MsgBox "Data Tidak Ditemukan", vbCritical
Call bersih
tcari.SetFocus
Else
With rsdatamobil
tkodemobil.Text = .Fields("kodemobil")
tmerk.Text = .Fields("merkmobil")
ttipe.Text = .Fields("tipemobil")
tplat.Text = .Fields("platnomor")
End With
Call nonaktif
tkodemobil.Enabled = False
cbsunting.Enabled = True
cbhapus.Enabled = True
cbbatal.Enabled = True
End If
rsdatamobil.Open "select*from tmobil where kodemobil='" & tcari.Text & "'", KON
If rsdatamobil.EOF Then
MsgBox "Data Tidak Ditemukan", vbCritical
Call bersih
tcari.SetFocus
Else
With rsdatamobil
tkodemobil.Text = .Fields("kodemobil")
tmerk.Text = .Fields("merkmobil")
ttipe.Text = .Fields("tipemobil")
tplat.Text = .Fields("platnomor")
End With
Call nonaktif
tkodemobil.Enabled = False
cbsunting.Enabled = True
cbhapus.Enabled = True
cbbatal.Enabled = True
End If
8.Klik pada cetak dan pastekan koding berikut :
cr.ReportFileName = "D:\Perkuliahan\Tugas Akhir\Tugas Akhir\program\Laporan\datamobil.rpt"
cr.WindowState = crptMaximized
cr.RetrieveDataFiles
cr.Action = 1
cr.WindowState = crptMaximized
cr.RetrieveDataFiles
cr.Action = 1
9.Klik pada bmenu dan pastekan koding berikut :
a = MsgBox("Yakin Untuk Menutup Form Ini Dan kembali ke Menu Utama ?", vbCritical + vbYesNo, "INFO")
If a = vbYes Then
fmobil.Hide
Call aktifadmin
End If
If a = vbYes Then
fmobil.Hide
Call aktifadmin
End If
10.Klik pada nodepan dan pastekan koding berikut (deklarasinya click) :
notengah.Enabled = True
nobelakang.Enabled = True
nobelakang.Enabled = True
11.Klik pada notengah dan pastekan koding berikut (deklarasi change):
If notengah.Text = "0" Then
MsgBox "Angka Tidak Valid", vbCritical
notengah.Text = ""
Else
End If
MsgBox "Angka Tidak Valid", vbCritical
notengah.Text = ""
Else
End If
12.Klik pada nobelakang dan pastekan koding berikut )deklarasi change( :
tplat.Text = nodepan.Text + notengah.Text + UCase(nobelakang.Text)
tplat.Enabled = False
Call koneksi
rsdatamobil.Open "select*from tmobil where platnomor='" & tplat.Text & "'", KON
If rsdatamobil.EOF Then
Call aktifsimpan
Else
MsgBox "Plat nomor kendaraan beroda empat telah terisi", vbCritical
notengah.Text = ""
nobelakang.Text = ""
nodepan.SetFocus
End If
tplat.Enabled = False
Call koneksi
rsdatamobil.Open "select*from tmobil where platnomor='" & tplat.Text & "'", KON
If rsdatamobil.EOF Then
Call aktifsimpan
Else
MsgBox "Plat nomor kendaraan beroda empat telah terisi", vbCritical
notengah.Text = ""
nobelakang.Text = ""
nodepan.SetFocus
End If
13.Buat sub aktif dan pastekan koding berikut :
tkodemobil.Enabled = True
tmerk.Enabled = True
ttipe.Enabled = True
tplat.Enabled = True
cbtambah.Enabled = True
cbsimpan.Enabled = True
cbsunting.Enabled = True
cbhapus.Enabled = True
cbperbarui.Enabled = True
cbbatal.Enabled = True
notengah.Enabled = True
nodepan.Enabled = True
nobelakang.Enabled = True
tmerk.Enabled = True
ttipe.Enabled = True
tplat.Enabled = True
cbtambah.Enabled = True
cbsimpan.Enabled = True
cbsunting.Enabled = True
cbhapus.Enabled = True
cbperbarui.Enabled = True
cbbatal.Enabled = True
notengah.Enabled = True
nodepan.Enabled = True
nobelakang.Enabled = True
14.Buat sub nonaktif dan pastekan koding berikut :
notengah.Enabled = False
nodepan.Enabled = False
nobelakang.Enabled = False
tkodemobil.Enabled = False
tmerk.Enabled = False
ttipe.Enabled = False
tplat.Enabled = False
cbtambah.Enabled = False
cbsimpan.Enabled = False
cbsunting.Enabled = False
cbhapus.Enabled = False
cbperbarui.Enabled = False
cbbatal.Enabled = False
nodepan.Enabled = False
nobelakang.Enabled = False
tkodemobil.Enabled = False
tmerk.Enabled = False
ttipe.Enabled = False
tplat.Enabled = False
cbtambah.Enabled = False
cbsimpan.Enabled = False
cbsunting.Enabled = False
cbhapus.Enabled = False
cbperbarui.Enabled = False
cbbatal.Enabled = False
15.Buat sub higienis dan pastekan koding berikut :
tkodemobil.Text = ""
tmerk.Text = ""
ttipe.Text = ""
tplat.Text = ""
tcari.Text = ""
notengah.Text = ""
nobelakang.Text = ""
tmerk.Text = ""
ttipe.Text = ""
tplat.Text = ""
tcari.Text = ""
notengah.Text = ""
nobelakang.Text = ""
16.Buat sub tampil dan pastekan koding berikut :
Call koneksi
rsdatamobil.Open "select*from tmobil", KON
Set grid.DataSource = rsdatamobil
rsdatamobil.Open "select*from tmobil", KON
Set grid.DataSource = rsdatamobil
17.Buat sub aktifadmin dan pastekan koding berikut :
fmenu.mlog.Enabled = True
fmenu.mganti.Enabled = True
fmenu.mdata.Enabled = True
fmenu.mdatauser.Enabled = True
fmenu.mdatabiaya.Enabled = True
fmenu.mdatasiswa.Enabled = False
fmenu.mriwayat.Enabled = True
fmenu.mlogout.Enabled = True
fmenu.mloguser.Enabled = False
fmenu.mmobil.Enabled = True
fmenu.mjam.Enabled = True
fmenu.mganti.Enabled = True
fmenu.mdata.Enabled = True
fmenu.mdatauser.Enabled = True
fmenu.mdatabiaya.Enabled = True
fmenu.mdatasiswa.Enabled = False
fmenu.mriwayat.Enabled = True
fmenu.mlogout.Enabled = True
fmenu.mloguser.Enabled = False
fmenu.mmobil.Enabled = True
fmenu.mjam.Enabled = True
18.Buat sub form_load dan pastekan koding berikut :
Call koneksi
Call nonaktif
Call tampil
cbtambah.Enabled = True
Me.Width = 13830
Me.Height = 8790
tmerk.MaxLength = 10
ttipe.MaxLength = 20
tplat.MaxLength = 10
Me.Left = 100
Me.Top = 0
notengah.MaxLength = 4
nobelakang.MaxLength = 3
Call nonaktif
Call tampil
cbtambah.Enabled = True
Me.Width = 13830
Me.Height = 8790
tmerk.MaxLength = 10
ttipe.MaxLength = 20
tplat.MaxLength = 10
Me.Left = 100
Me.Top = 0
notengah.MaxLength = 4
nobelakang.MaxLength = 3
19.Buat sub aktifsimpan dan pastekan koding berikut :
If cbperbarui.Enabled = True Then
cbsimpan.Enabled = False
Else
cbsimpan.Enabled = True
End If
cbsimpan.Enabled = False
Else
cbsimpan.Enabled = True
End If
Sumber http://www.hendrisetiawan.com