Selasa, 03 April 2012

Membuat Progra Sederhana dengan menggunakan Visual Basic 6.0

Membuat Progra Sederhana dengan menggunakan Visual Basic 6.0
ini adalah langkah - langkah sederhana dalam membua suatu Program dengan menggunakan visual Basic 6.0
Berikut ini adalah langkah-langkah sederhananya:
1.    Form Menu
·         Klik kanan pada Form, pilih Menu Editor.
·         Lalu isi Menu2 yang akan di buat.
Private Sub Form_Load()
frmmenu.mdata.Visible = False
frmmenu.mtransaksi.Visible = False
frmmenu.mlaporan.Visible = False
End Sub
Private Sub mcdosen_Click()
frmpcdosen.Show
End Sub
Private Sub mcmahasiswa_Click()
frmpcmahasiswa.Show
End Sub
Private Sub mdosen_Click()
frmdosen.Show
End Sub
Private Sub mlogin_Click()
frmlogin.Show
End Sub
Private Sub mlogout_Click()
frmmenu.mdata.Visible = False
frmmenu.mtransaksi.Visible = False
frmmenu.mlaporan.Visible = False
frmmenu.mlogin.Visible = True
frmmenu.mlogout.Visible = False
End Sub
Private Sub mmahasiswa_Click()
frmmahasiswa.Show
End Sub
Private Sub mselesai_Click()
frmmenu.Hide
End Sub
Private Sub msmahasiswa_Click()
frmsvmahasiswa.Show
End Sub
Private Sub Timer1_Timer()
Text1 = Format(Now, "DD/MM/YY")
Text2 = Format(Now, "HH.MM.SS")
End Sub
 
2.    Form Mahasiswa
·         Di “ADODC” – RSMAHASISWA, klik kanan pilih ADODC properties.



 
Private Sub Command1_Click()
RSMAHASISWA.Recordset.MoveFirst
TAMPIL
End Sub
Private Sub TAMPIL()
Text1 = RSMAHASISWA.Recordset.Fields(0)
Text2 = RSMAHASISWA.Recordset.Fields(1)
Text3 = RSMAHASISWA.Recordset.Fields(2)
Text4 = RSMAHASISWA.Recordset.Fields(3)
Text5 = RSMAHASISWA.Recordset.Fields(4)
Text6 = RSMAHASISWA.Recordset.Fields(5)
Text7 = RSMAHASISWA.Recordset.Fields(6)
Text8 = RSMAHASISWA.Recordset.Fields(7)
Text9 = RSMAHASISWA.Recordset.Fields(8)
End Sub
Private Sub Command2_Click()
RSMAHASISWA.Recordset.MovePrevious
If RSMAHASISWA.Recordset.BOF Then
    MsgBox ("Ini Data Pertama")
    RSMAHASISWA.Recordset.MoveFirst
End If
TAMPIL
End Sub
Private Sub Command3_Click()
RSMAHASISWA.Recordset.MoveNext
If RSMAHASISWA.Recordset.EOF Then
    MsgBox ("Ini Data Terakhir")
    RSMAHASISWA.Recordset.MoveLast
End If
TAMPIL
End Sub
Private Sub Command4_Click()
RSMAHASISWA.Recordset.MoveLast
TAMPIL
End Sub
Private Sub Command5_Click()
RSMAHASISWA.Refresh
End Sub
Private Sub Form_Load()
RSMAHASISWA.Refresh
TAMPIL
End Sub
 
3.    Form Dosen
 
Private Sub Command1_Click()
RSDOSEN.Recordset.MoveFirst
TIMBUL
End Sub
Private Sub TIMBUL()
Text1 = RSDOSEN.Recordset.Fields(0)
Text2 = RSDOSEN.Recordset.Fields(1)
Text3 = RSDOSEN.Recordset.Fields(2)
Text4 = RSDOSEN.Recordset.Fields(3)
Text5 = RSDOSEN.Recordset.Fields(4)
Text6 = RSDOSEN.Recordset.Fields(5)
Text7 = RSDOSEN.Recordset.Fields(6)
Text8 = RSDOSEN.Recordset.Fields(7)
Text9 = RSDOSEN.Recordset.Fields(8)
End Sub
Private Sub Command2_Click()
RSDOSEN.Recordset.MovePrevious
If RSDOSEN.Recordset.BOF Then
    MsgBox ("Ini Data Pertama")
    RSDOSEN.Recordset.MoveFirst
End If
TIMBUL
End Sub
Private Sub Command3_Click()
RSDOSEN.Recordset.MoveNext
If RSDOSEN.Recordset.EOF Then
    MsgBox ("Ini Data Terakhir")
    RSDOSEN.Recordset.MoveLast
End If
TIMBUL
End Sub
Private Sub Command4_Click()
RSDOSEN.Recordset.MoveLast
TIMBUL
End Sub
Private Sub Command5_Click()
RSDOSEN.Refresh
End Sub
Private Sub Form_Load()
RSDOSEN.Refresh
TIMBUL
End Sub
  
4.    Form Pencarian Mahasiswa
Private Sub Command1_Click()
On Error Resume Next
RSMAHASISWA.CommandType = adCmdText
RSMAHASISWA.RecordSource = Text2
RSMAHASISWA.Refresh
Text1 = RSMAHASISWA.Recordset.RecordCount
End Sub
5.    Form Pencarian Dosen
Private Sub Command1_Click()
On Error Resume Next
RSDOSEN.CommandType = adCmdText
RSDOSEN.RecordSource = Text2
RSDOSEN.Refresh
Text1 = RSDOSEN.Recordset.RecordCount
End Sub
6.    Form Login
Private Sub Command1_Click()
If Text1 = "" Then
    MsgBox ("USER NAMA TIDAK BOLEH KOSONG")
Text1.SetFocus
Exit Sub
End If
If Text2 = "" Then
  MsgBox ("PASSWORD TIDAK BOLEH KOSONG")
Text2.SetFocus
Exit Sub
End If
RSLOGIN.CommandType = adCmdText
RSLOGIN.RecordSource = "select * from Login where username='" & Text1 & "' and kode='" & Text2 & "'"
RSLOGIN.Refresh
If RSLOGIN.Recordset.EOF Then
    MsgBox ("Username/Password Ada Kesalahan")
    Text1 = Clear
    Text2 = Clear
    Text1.SetFocus
Else
    MsgBox ("VERIFIKASI PASSWORD BENAR")
Unload Me
frmmenu.mdata.Visible = True
frmmenu.mtransaksi.Visible = True
frmmenu.mlaporan.Visible = True
End If
frmmenu.mlogin.Visible = False
frmmenu.mlogout.Visible = True
End Sub
Private Sub Command2_Click()
frmlogin.Hide
End Sub
Private Sub Form_Load()
frmlogin.Refresh
Text1 = Clear
Text2 = Clear
End Sub
7.  Form Penyimpanan Mahasiswa
 
Private Sub BERSIH()
Text2 = Clear
Text3 = Clear
Text4 = Clear
Text6 = Clear
Text7 = Clear
Text8 = Clear
Text9 = Clear
End Sub
Private Sub TAMPILDATA()
RSMAHASISWA.CommandType = adCmdText
RSMAHASISWA.RecordSource = "select * from mahasiswa"
RSMAHASISWA.Refresh
DataGrid1.Refresh
End Sub
Private Sub cmdbaru_Click()
BERSIH
Text1 = Clear
Text1.SetFocus
End Sub
Private Sub cmdbatal_Click()
BERSIH
TAMPILDATA
cmdhapus.Enabled = False
cmdedit.Enabled = False
cmdsimpan.Enabled = False
End Sub
Private Sub cmdcetak_Click()
Hadi.ReportFileName = App.Path + "/lapmahasiswa.rpt"
Hadi.RetrieveDataFiles
Hadi.WindowState = crptMaximized
Hadi.Action = 1
End Sub
Private Sub cmdedit_Click()
RSMAHASISWA.Recordset.Fields(1) = Text2
RSMAHASISWA.Recordset.Fields(2) = Text3
RSMAHASISWA.Recordset.Fields(3) = Text4
RSMAHASISWA.Recordset.Fields(4) = DTPicker1.Value
RSMAHASISWA.Recordset.Fields(5) = Text6
RSMAHASISWA.Recordset.Fields(6) = Text7
RSMAHASISWA.Recordset.Fields(7) = Text8
RSMAHASISWA.Recordset.Fields(8) = Text9
RSMAHASISWA.Recordset.Update
MsgBox ("Data Telah DiEdit")
RSMAHASISWA.Refresh
TAMPILDATA
End Sub
Private Sub cmdhapus_Click()
A = MsgBox("Yakin Akan Dihapus....??", vbYesNo, "")
If A = vbYes Then
    RSMAHASISWA.Recordset.Delete
    RSMAHASISWA.Refresh
Else
    Cancel = True
End If
    Text1 = Clear
    Text1.SetFocus
    cmdhapus.Enabled = False
    cmdedit.Enabled = False
    cmdsimpan.Enabled = False
    BERSIH
    TAMPILDATA
End Sub
Private Sub cmdselesai_Click()
frmsvmahasiswa.Hide
End Sub
Private Sub cmdsimpan_Click()
If Text1 = "" Then
    MsgBox ("NIS Harap Diisi")
    Exit Sub
End If
If Text2 = "" Then
    MsgBox ("Nama Harap Diisi")
    Exit Sub
End If
RSMAHASISWA.Recordset.AddNew
RSMAHASISWA.Recordset.Fields(0) = Text1
RSMAHASISWA.Recordset.Fields(1) = Text2
RSMAHASISWA.Recordset.Fields(2) = Text3
RSMAHASISWA.Recordset.Fields(3) = Text4
RSMAHASISWA.Recordset.Fields(4) = DTPicker1.Value
RSMAHASISWA.Recordset.Fields(5) = Text6
RSMAHASISWA.Recordset.Fields(6) = Text7
RSMAHASISWA.Recordset.Fields(7) = Text8
RSMAHASISWA.Recordset.Fields(8) = Text9
RSMAHASISWA.Recordset.Update
MsgBox ("Data Anda Telah Tersimpan")
RSMAHASISWA.Refresh
TAMPILDATA
End Sub
Private Sub DTPicker1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Text6.SetFocus
End If
End Sub
Private Sub Form_Load()
Text1 = Clear
cmdhapus.Enabled = False
cmdedit.Enabled = False
cmdsimpan.Enabled = False
BERSIH
RSMAHASISWA.Refresh
Text1.MaxLength = 5
Text6.MaxLength = 2
Text9.MaxLength = 3
End Sub
Private Sub Text1_Change()
Dim panjang As Byte
panjang = Len(Text1)
If panjang < 5 Then
    Exit Sub
End If
RSMAHASISWA.CommandType = adCmdText
RSMAHASISWA.RecordSource = "select * from mahasiswa where NIS='" & Text1 & "'"
RSMAHASISWA.Refresh
If Not RSMAHASISWA.Recordset.EOF Then
    MsgBox ("NIS Sudah Ada")
    Text2 = RSMAHASISWA.Recordset.Fields(1)
    Text3 = RSMAHASISWA.Recordset.Fields(2)
    Text4 = RSMAHASISWA.Recordset.Fields(3)
    DTPicker1.Value = RSMAHASISWA.Recordset.Fields(4)
    Text6 = RSMAHASISWA.Recordset.Fields(5)
    Text7 = RSMAHASISWA.Recordset.Fields(6)
    Text8 = RSMAHASISWA.Recordset.Fields(7)
    Text9 = RSMAHASISWA.Recordset.Fields(8)
    cmdsimpan.Enabled = False
    cmdhapus.Enabled = True
    cmdedit.Enabled = True
Else
    BERSIH
    Text2.SetFocus
    cmdsimpan.Enabled = True
    cmdhapus.Enabled = False
    cmdedit.Enabled = False
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
    DTPicker1.SetFocus
End If
End Sub
Private Sub Text6_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Text7.SetFocus
End If
End Sub
Private Sub Text7_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Text8.SetFocus
End If
End Sub
Private Sub Text8_Change()
If KeyAscii = 13 Then
    Text9.SetFocus
End If
End Sub

sekian dulu cara sederhana membuat program berbasis Visual Basic 6.0 yang dapat saya sajikan. mohon maaf jika ada kesalahan .
SELAMAT MENCOBA

Tidak ada komentar:

Posting Komentar