Selasa, 05 Februari 2013

Membuat Form Menambahkan Foto pada VB 6.0

sebelum saya mengucapkan selalamat berjuang bagi teman2 kelas 3 RPL,. karena sebentar lagi akan mengadakan ujian kompetensi,..

berhubungan dengan soal ujian kompetensi sudah keluar dan ada paket yang membutuhkan form yang ada menampilkan foto dan menyimpan foto,.. saya coba sedikit membantu teman-teman,.

berikut cara membuatnya

1. pertama kita rancang formnya seperti gambar di bawah ini

2. tambahkan commponents Microsoft ADO Data Control 6.0 (OLEDB) dan Microsoft Common Dialog Control 6.0



3. Buat data basenya untuk menampung file atau data yang akan kita simpan
kemudian tambah table dan atur seperti gambar di bawah ini


type field nya text semua,.. dan sizenya kita atur seperlunya

4. setelah selesai membuat data base kita kembali ke form dan masukkan script di bawah ini


Dim db As ADODB.Connection
Dim RS As ADODB.Recordset
Private Sub bersih()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text1.Enabled = True
Text1.SetFocus
Combo1.Text = "Tgl"
Combo2.Text = "Bulan"
Combo3.Text = "Tahun"
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
    If keyasii = 13 Then
    Combo2.SetFocus
    End If
End Sub

Private Sub Combo2_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Combo3.SetFocus
    End If
End Sub

Private Sub Combo3_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Command1.SetFocus
    End If
End Sub

Private Sub Command1_Click()
    If Command1.Caption = "Simpan" Then
    db.Execute ("insert into siswa (siswa_nisn,kompetensi_kode,siswa_nama,siswa_alamat,siswa_tgl_lahir,siswa_bln_lahir,siswa_thn_lahir,foto)values " & _
    "('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "','" & Combo1 & "','" & Combo2 & "','" & Combo3 & "','" & Text5 & "')")
    MsgBox "data tersimpan"
    Call bersih
    Command1.Enabled = False
    Command2.Enabled = False
    Else
    Command1.Caption = "Perbarui"
    db.Execute ("update siswa set kompetensi_kode='" & Text2 & "',siswa_nama='" & Text3 & "',siswa_alamat='" & Text4 & "' " & _
    ",siswa_tgl_lahir='" & Combo1 & "',siswa_bln_lahir='" & Combo2 & "',siswa_thn_lahit='" & Combo3 & "',foto='" & Text5 & "' where bidang_kode='" & Text1 & "'")
    MsgBox "Data di Perbarui"
    Command1.Enabled = False
    Command2.Enabled = False
    Call bersih
    End If
End Sub
Private Sub cari()
    Set RS = db.Execute("select*from siswa where siswa_nisn='" & Text1.Text & "'")
    If Not RS.EOF Then
    Text2 = RS!kompetensi_kode
    Text3 = RS!siswa_nama
    Text4 = RS!siswa_alamat
    Combo1 = RS!siswa_tgl_lahir
    Combo2 = RS!siswa_bln_lahir
    Combo3 = RS!siswa_thn_lahir
    Text5 = RS!foto
    'CommonDialog1.FileName = rsmhs.Fields(7)
    'Image1.Picture = LoadPicture(App.Path & "\foto\" & Text1.Text & ".jpg")
    Command1.Caption = "Perbarui"
    Text1.Enabled = False
    End If
End Sub

Private Sub Command2_Click()
    If MsgBox("Anda Yakin", vbQuestion + vbYesNo, "Keluar") = vbYes Then
    db.Execute ("delete from siswa where siswa_nisn ='" & Text1 & "'")
    Command1.Enabled = False
    Command2.Enabled = False
    Command1.Caption = "Simpan"
    Call bersih
    End If
End Sub

Private Sub Command3_Click()
    Call bersih
    'Image1.Refresh
    Command1.Enabled = False
    Command2.Enabled = False
    Command1.Caption = "Simpan"
End Sub

Private Sub Command4_Click()
    If MsgBox("Anda Yakin", vbQuestion + vbYesNo, "Keluar") = vbYes Then
    Unload Me
    End If
End Sub

Private Sub Command5_Click()
    CommonDialog1.ShowOpen
Text5 = CommonDialog1.FileName
End Sub

Private Sub Form_Activate()
    Call bersih
    Command1.Enabled = False
    Command2.Enabled = False
    Text5.Enabled = False
End Sub

Private Sub Form_Load()
    Set db = New ADODB.Connection
    Set RS = New ADODB.Recordset
    db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Visual Basic\menambah foto\uk_rpl_2013.mdb;Persist Security Info=False"
    'tgl
    For tgl = 1 To 31
    Combo1.AddItem tgl
    Next tgl
    'bulan
    For bulan = 1 To 12
    Combo2.AddItem bulan
    Next bulan
    'tahun
    For tahun = 1990 To 2020
    Combo3.AddItem tahun
    Next tahun
    Command1.Caption = "Simpan"
End Sub

Private Sub Image1_Click()
LoadPicture
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    'Image1.Picture = LoadPicture(App.Path & "\foto\" & Text1.Text & ".jpg")
    Call cari
    Text2.SetFocus
    Command1.Enabled = True
    Command2.Enabled = True
    End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Text3.SetFocus
    End If
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Text4.SetFocus
    End If
End Sub

Private Sub Text4_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
    Combo1.SetFocus
    End If
End Sub

Private Sub Text5_Change()
    Image1.Picture = LoadPicture(Text5)
End Sub

5. setelah selesai silahkan di jalankan programnya,. semoga berhasil

bagi yang ingin mendowload filenya silahkan download disini

1 komentar:

 
Copyright © . cempiyai - Posts · Comments
Theme Template by BTDesigner · Powered by Blogger