MODUL
PRAKTEK SISWA RPL
MEMBUAT PROGRAM MOTOR
A. Persiapan
-Visual Basic 6.0
-Wamp Server
-My SQL ODBC
B. Selanjutnya
Kita membuat Databasenya
Nama Database = rpl_ok
1. Tabel1=
motor
C. Membuat
From Dan Script Program
D.LALU KONEKSI ODBC
SETELAH ITU PILIH ADD
ISI DSN dengan nama dsnrpl_ok
Database rpl_ok
Username root
Perancangan Script
A.Script koneksi ODBC harus Diketik
Dim db As ADODB.Connection KEDUA SINTAK INI TIDAK BOLEH DIKETIK
Dim rs As ADODB.Recordset
B. MEMBUAT KONEKSI KE MYSQL
Private Sub Form_Load()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.CursorLocation = adUseClient
db.Open
"provider=msdasql.1;persist security info=false;Data
source=dsnrpl_ok"
Combo1.AddItem "RANDOM"
Combo1.AddItem "YAMAHA"
Combo1.AddItem "SUZUKI"
Combo1.AddItem "KAWASAKI"
Combo1.AddItem "HONDA"
Combo2.AddItem "RAMDOM"
Combo2.AddItem "PUTIH"
Combo2.AddItem "MERAH"
Combo2.AddItem "UNGU"
Combo2.AddItem "HIJAU"
Combo2.AddItem "HITAM"
Call tampil_data_motor
End Sub
C. Menampilkan Semua Data
Melalui Data grid
Private Sub
tampil_data_motor()
Set rs =
db.Execute("select*from motor")
Set DataGrid1.DataSource = rs
D. Membuat tampilan awal form motor
Private Sub
tampilan_awal_form()
Text1 = ""
Text2 = ""
Text3 = ""
Combo1 = ""
Combo2 = ""
Text2.Enabled = True
Text3.Enabled = True
Combo1.Enabled = True
Combo2.Enabled = True
Command1.Caption =
"SIMPAN"
Command2.Enabled = True
Command1.Enabled = True
Text1.SetFocus
End Sub
E.Kemudian membuat Script tampilan_awal_form_active
Private Sub
form_Active()
Call tampil_awal_form
End Sub
F. Membuat iven keypress
Private Sub Combo1_keyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.Enabled = True
Text2.SetFocus
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo2.Enabled = True
Combo2.SetFocus
End If
End Sub
Private Sub combo2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.Enabled = True
Text3.SetFocus
End If
End Sub
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1.Enabled = True
Command1.SetFocus
End If
End Sub
G. Membuat Tombol BATAL
Private Sub Command1_Click()
If
Command1.Caption = "SIMPAN" Then
db.Execute
("insert into motor(kodemotor,merk,nama,warna,harga)values('" &
Text1.Text & "','" & Combo1 & "','" &
Text2.Text & "','" & Combo2 & "','" &
Text3.Text & "')")
Call
tampil_data_motor
Else
db.Execute
("update motor set merk='" & Combo1 & "',nama='"
& Text2 & "',warna='" & Combo2 &
"',harga='" & Text3 & "' where kodemotor='" &
Text1 & "'")
Call
tampil_data_motor
End If
End Sub
H.Membuat Tombol KELUAR
Private Sub
Command4_Click()
Unload Me
End Sub
I.Membuat Tombol SIMPAN
Private Sub
Command1_Click()
If Command1.Caption = "SIMPAN" Then
db.Execute ("insert into
motor(kodemotor,merk,nama,warna,harga)values('" & Text1.Text & "','"
& Combo1 & "','" & Text2.Text & "','" &
Combo2 & "','" & Text3.Text & "')")
Call tampil_data_motor
Else
db.Execute ("update motor set merk='" & Combo1
& "',nama='" & Text2 & "',warna='" & Combo2
& "',harga='" & Text3 & "' where kodemotor='"
& Text1 & "'")
Call
tampil_data_motor
End If
End Sub
J.Membuat
Tombol HAPUS
Private Sub Command2_Click()
db.Execute
("delete from motor where kodemotor='" & Text1.Text &
"'")
Call
tampil_data_motor
Call
tampilan_awal_form
End Sub
0 komentar:
Posting Komentar