Membuat Aplikasi
Sederhana Dengan Menambahkan Gambar
Bagi teman-teman
yang tertarik membuat program Data Mahasiswa dengan melampirkan foto
mahasiswanya dapat mengikuti langkah-langkah berikut ini
Pertama-tama Buatlah sebuah table dengan
struktur sebagai berikut :
Setelah itu desain Form seperti berikut ini
Setelah selesai mendesai Form lanjutkan ketahap berikutnya yaitu atur
propertynya seperti berikut ini
Form1
Nama : frmmahasiswa
Caption : Data Mahasiswa
Picture : (Pilih Gambar Yang Anda Inginkan)
Text1
Name : txtnim
Text : -
BorderStyle : 1- Fixed Single
Text2
Name : txtnama
Text : -
BorderStyle : 1- Fixed Single
Text3
Name : txtfakultas
Text : -
BorderStyle : 1- Fixed Single
Text4
Name : txtjurusan
Text : -
BorderStyle : 1- Fixed Single
Text5
Name : txtangkatan
Text : -
BorderStyle : 1- Fixed Single
Text6
Name : txtfoto
Text : -
BorderStyle : 1- Fixed Single
Label1
Caption : NIM
BackStyle:
0-Transparent
Label2
Caption : Nama
BackStyle:
0-Transparent
Label3
Caption : Fakultas
BackStyle:
0-Transparent
Label4
Caption : Jurusan
BackStyle:
0-Transparent
Label5
Caption : Angkatan
BackStyle:
0-Transparent
Label6
Caption : iswandibaras@ymail.com
BackStyle:
0-Transparent
ForeColor : Red
Command1
Caption : Simpan
Name : cmdsimpan
Command2
Caption : Edit
Name : cmdedit
Command3
Caption : Hapus
Name : cmdhapus
Command4
Caption : Ubah
Foto
Name : cmdfoto
Command5
Caption : Cetak
Name : cmdcetak
Command6
Caption : Keluar
Name : cmdkeluar
Timer
Interval : 200
Commondialog
Picture : Defaul
(Foto Dari Komputer Anda)
BorderStyle : 1- Fixed Single
Sehingga hasil
desainnya seperti gambar berikut
Kemudian isi kode
program dengan listing di bawa ini
Private Sub
cmdcetak_Click()
DataReport1.Show
End Sub
Private Sub
cmdhapus_Click()
Data1.Recordset.Delete
Data1.Refresh
kosong
Image1.Picture =
LoadPicture("E:\Foto\Is One &I\isi.jpg")
MsgBox "Data Telah Dihapus",
vbOKOnly + vbInformation, "Is O^e &!.."
txtnim.SetFocus
cmdsimpan.Enabled = False: cmdhapus.Enabled
= False: cmdedit.Enabled = False: cmdfoto.Enabled = False
End Sub
Private Sub
Form_Activate()
txtnim.SetFocus
kosong
Image1.Picture =
LoadPicture("E:\Foto\Is One &I\isi.jpg")
cmdsimpan.Enabled = False: cmdhapus.Enabled
= False: cmdedit.Enabled = False: cmdfoto.Enabled = False
End Sub
Private Sub
kosong()
txtnim = "": txtnama =
"": txtfakultas = "": txtjurusan = "":
txtangkatan = "": txtfoto = ""
End Sub
Private Sub
Form_Load()
kosong
'nonaktifkan tombol
cmdsimpan.Enabled = False: cmdedit.Enabled
= False:
cmdfoto.Enabled = False: cmdhapus.Enabled =
False
End Sub
Private Sub
Form_Unload(Cancel As Integer)
Image1.Picture = LoadPicture("")
End Sub
Private Sub
Timer1_Timer()
If Label5(1).ForeColor = &HFF& Then
Label5(1).ForeColor = &HFF0000
ElseIf Label5(1).ForeColor = &HFF0000
Then
Label5(1).ForeColor = &H8080&
ElseIf Label5(1).ForeColor =
&H8080& Then
Label5(1).ForeColor = &H800080
ElseIf Label5(1).ForeColor = &H800080
Then
Label5(1).ForeColor = &HFF&
End If
End Sub
Private Sub
txtnim_Change()
Data1.Refresh
Dim namagbr As String
Dim gbrkosong As String
On Error Resume Next
If Len(Trim(txtnim)) < 12 Then
Exit Sub
End If
With Data1.Recordset
.Index = "idxNIM"
.Seek "=", txtnim
If Not .NoMatch Then
txtnim.Text = !nim
txtnim.SetFocus
txtnama = !NAMA
txtfakultas = !FAKULTAS
txtjurusan = !JURuSAN
txtangkatan = !ANGKATAN
txtfoto = !FOTO
'menampilkan foto
namagbr = "E:\Foto\Is One
&I\" & Trim(txtfoto.Text) & ""
Image1.Picture = LoadPicture(namagbr)
'memunculkan beberapa tombol
cmdedit.Caption = "Edit":
cmdedit.Enabled = True: cmdhapus.Enabled = True: cmdsimpan.Enabled = False:
cmdsimpan.Caption = "Batal": cmdkeluar.Caption = "Keluar"
Else
pesan = MsgBox("Yakin Ingin Menyimpan
Data.?", vbYesNo + vbInformation, "Is O^e &!..")
If pesan = vbYes Then
txtnama = "": txtfakultas =
"": txtjurusan = "": txtangkatan = "": txtfoto =
""
txtnama.SetFocus
bisaisi
gbrkosong = "E:\Foto\Is One
&I\isi.jpg"
Image1.Picture = LoadPicture(gbrkosong)
'pengaturan tombol
cmdsimpan.Caption = "Simpan"
cmdedit.Enabled = False
cmdhapus.Enabled = False
cmdfoto.Enabled = True
Else
Image1.Picture =
LoadPicture("E:\Foto\Is One &I\isi.jpg")
Form_Load
End If
End If
End With
On Error GoTo 0
End Sub
Sub bisaisi()
txtnama.SetFocus
cmdsimpan.Enabled = True
cmdkeluar.Caption = "Batal"
End Sub
Private Sub
cmdedit_Click()
On Error Resume Next
If cmdedit.Caption = "Edit" Then
'menonaktifkan tombol hapus dan keluar
cmdhapus.Enabled = False
cmdkeluar.Enabled = False
cmdsimpan.Caption = "Batal":
cmdsimpan.Enabled = True
'aktifkan tombol ubahfoto
cmdfoto.Enabled = True
If txtnim = "" Then
MsgBox "Masukkan Kode Nim Yang Akan
Diedit.!", 0, "Is O^e &!.."
txtnim.SetFocus
Else
txtnama.SetFocus
cmdedit.Caption = "Update"
End If
Else
With Data1.Recordset
.Edit
!nim = txtnim
!NAMA = txtnama
!FAKULTAS = txtfakultas
!JURuSAN = txtjurusan
!ANGKATAN = txtangkatan
!FOTO = txtfoto
.Update
Data1.Refresh
End With
MsgBox "Data Telah Diubah", 0,
"Is O^e &!.."
kosong
Image1.Picture =
LoadPicture("E:\Foto\Is One &I\isi.jpg")
txtnim.SetFocus
cmdedit.Caption = "Edit"
'pengaturan tombol
cmdedit.Enabled = False: cmdhapus.Enabled =
False: cmdkeluar.Enabled = True: cmdsimpan.Enabled = False: cmdfoto.Enabled =
False
'pengaturan awal
kosong
txtnim.SetFocus
End If
On Error GoTo 0
End Sub
Private Sub
cmdfoto_Click()
On Error GoTo Ooops
CommonDialog1.ShowOpen
txtfoto.Enabled = False
txtfoto = CommonDialog1.FileTitle
Image1.Picture = LoadPicture(txtfoto)
On Error GoTo 0
Exit Sub
Ooops:
MsgBox "File Error !", 0,
"Is O^e &!.."
End Sub
Private Sub
cmdkeluar_Click()
If cmdkeluar.Caption = "Batal"
Then
'pengaturan awal
Form_Load
kosong
Image1.Picture =
LoadPicture("E:\Foto\Is One &I\isi.jpg")
txtnim.SetFocus
cmdkeluar.Caption = "Keluar"
'pengaturan tombol
cmdsimpan.Enabled = False
cmdedit.Enabled = False
cmdhapus.Enabled = False
Else
frmmenu.Show
Form1.Hide
End If
End Sub
Private Sub
cmdsimpan_Click()
If
cmdsimpan.Caption = "Batal" Then
kosong
cmdkeluar.Enabled
= True: cmdsimpan.Enabled = False: cmdedit.Enabled = False: cmdfoto.Enabled =
False: Image1.Picture = LoadPicture("E:\Foto\Is One &I\isi.jpg")
txtnim.SetFocus
End If
Exit Sub
With
Data1.Recordset
.Index = "idxnim"
.Seek "=", txtnim
If Not .NoMatch Then
MsgBox "Nim Telah Digunakan",
vbOKOnly + vbInformation, "Is O^e &!.."
txtnim = ""
txtnim.SetFocus
Else
isi = MsgBox("Yakin Ingin Mengisi
Data.?", vbYesNo + vbInformation, "Is O^e &!..")
If isi = vbYes Then
txtnama.SetFocus
Else
kosong
End If
End If
End With
On Error Resume Next
If cmdsimpan.Caption = "Simpan"
Then
With Data1.Recordset
.AddNew
!nim = txtnim
!NAMA = txtnama
!FAKULTAS = txtfakultas
!JURuSAN = txtjurusan
!ANGKATAN = txtangkatan
!FOTO = txtfoto
.Update
Data1.Refresh
MsgBox "Data Telah Disimpan",
vbOKOnly + vbInformation, "Is O^e &!.."
Data1.Refresh
kosong
Image1.Picture =
LoadPicture("E:\Foto\Is One &I\isi.jpg")
txtnim.SetFocus
End With
Else
kosong
Image1.Picture =
LoadPicture("E:\Foto\Is One &I\isi.jpg")
txtnim.SetFocus
cmdkeluar.Caption = "Keluar"
cmdsimpan.Caption = "Simpan"
'pengaturan tombol
cmdsimpan.Enabled = False: cmdedit.Enabled
= False: cmdhapus.Enabled = False: cmdfoto.Enabled = False: cmdkeluar.Enabled =
True
End If
On Error GoTo 0
End Sub
Kemudian start
programnya input data dan isi fotonya.
Contoh dari
program yang telah saya buat seperti gambar berikut ini:
Gimana kawan-kawan..??
Unikkan.?
Selamat mencoba
semoga sukses
Catatan : bila
ingin copy paste artikel ini di blog anda jangan lupa cantungkan sumbernya
www.iswandifikom.blogspot.com bagi kawan-kawan yang mau download programnya dapat kelik disini
Tidak ada komentar:
Posting Komentar