Latihan Visual Basic (Prak Lab)
Latihan Visual Basic (Prak Lab)
Coding
untuk tombol (Tambah) :
Text1.Text = " "
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
Combo1.ListIndex = 0
Text1.SetFocus
Coding untuk tombol (Simpan) :
Data1.Recordset.AddNew
Data1.Recordset!kodebuku = Text1.Text
Data1.Recordset!judulbuku = Text2.Text
Data1.Recordset!Penerbit = Text3.Text
Data1.Recordset!jenisbuku = Combo1.Text
Data1.Recordset!jumlahbuku = Text4.Text
Data1.Recordset.Update
Text1.Text = "
"
Text2.Text = "
"
Text3.Text = "
"
Text4.Text = "
"
Combo1.ListIndex = 0
Text1.SetFocus
MsgBox "Data telah tersimpan", vbOKOnly + vbInformation,
"Info"
Coding untuk tombol (Edit) :
Data1.Recordset.Edit
Data1.Recordset!kodebuku = Text1.Text
Data1.Recordset!judulbuku = Text2.Text
Data1.Recordset!Penerbit = Text3.Text
Data1.Recordset!jenisbuku = Combo1.Text
Data1.Recordset!jumlahbuku = Text4.Text
Data1.Recordset.Update
Text1.Text = "
"
Text2.Text = "
"
Text3.Text = "
"
Text4.Text = "
"
Combo1.ListIndex = 0
Text1.SetFocus
MsgBox "Data telah di edit ", Vbokony + vbInformation,
"Info"
Coding untuk tombol (Hapus) :
Dim Hapus As String
Hapus = MsgBox("Yakin anda mau menghapus?", vbYesNo +
vbQuestion, "konfirmasi")
If Hapus = vbYes Then
Data1.Recordset.Delete
MsgBox "Data telah terhapus", vbOKOnly + vbInformation,
"Info"
Text1.Text = "
"
Text2.Text = "
"
Text3.Text = "
"
Text4.Text = "
"
Combo1.Text = "
"
Text1.SetFocus
End If
Coding untuk tombol (Keluar) :
Unload Me
Coding untuk set keyassci-nya bisa di terawang di bawah ini :
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
If KeyAscii = 13 Then
Data1.Recordset.Index = "kode"
Data1.Recordset.Seek "=", Text1.Text
If Not Data1.Recordset.NoMatch Then
Text2.Text = Data1.Recordset!judulbuku
Combo1.Text = Data1.Recordset!jenisbuku
Text3.Text = Data1.Recordset!Penerbit
Text4.Text = Data1.Recordset!jumlahbuku
Else
MsgBox " maaf data tidak terdaftar ", vbOKOnly +
vbInformation, "konfirmasi"
Text1.Text = "
"
Text2.Text = " "
Text3.Text = "
"
Text4.Text = "
"
Combo1.ListIndex = 0
Text1.SetFocus
End If
End If
Untuk menambahkan no urut secara otomatis, pada tombol
tambah bisa di tambah coding sbb :
On Error Resume Next
Dim nob As Long
Dim nol As String
If Data3.Recordset.BOF
And Data3.Recordset.EOF Then
nob = 1
Else
Data3.Recordset.MoveLast
nob =
Val(Data3.Recordset!nokembali) + 1
End If
Text8.Text =
Left("00000", 6 - Len(Trim(Str(nob)))) & Trim(Str(nob))
Text4.SetFocus
Komentar
Posting Komentar