Modul Latihan dan Jawaban - Visual Basic 6

					                                                Modul Latihan [VISUAL BASIC] – Aep.Darmawan


                                  Latihan Visual Basic

Buatlah Database karyawan, dengan 3 tabel yang terdiri dari tabel karyawan, dan tabel
golongan, dan tabel transaksi


                               Database Karyawan


            Tabel Karyawan            Tabel Golongan               Tabel Transaksi

          Nip                      Golongan
                                                                 Tanggal
          Nama                     TunjanganGol
                                                                 Nip
          Golongan                 IuranWajib
                                                                 Nama
          TglLahir
                                                                 Golongan
          JenisKelamin
                                                                 Gajipokok
          Status
                                                                 TunjanganGol
          Jumlah Anak
                                                                 TunjanganIstri
          Gajipokok
                                                                 TunjanganAnak
                                                                 Pinjaman
                                                                 IuranWajib
                                                                 IuranSukarela




Tabel karyawan
        Field                  Tipe        Size        Index
        Nip                    Text        9           Primary
        Nama                   Text        25
        Golongan               Text        4
        Jkel                   Text        10
        Tgllahir               Date
        Status                 Num         1
        Gapok                  Num         12
        JmlAnak                Num         2

Tabel Golongan
       Field                   Tipe        Size        Index
       Golongan                Text        4           Primary
       TunjGol                 Num         12
       IuranWajib              Num         12




                                                                                 Halaman 1
                                                                     © A.D. – Bandung 2005
                                                 Modul Latihan [VISUAL BASIC] – Aep.Darmawan

Tabel Transaksi
        Field                  Tipe         Size       Index
        Tanggal                Date
        Nip                    Text         9
        Nama                   Text         25
        Golongan               Text         4
        Gapok                  Num          12
        TunjGol                Num          12
        TunjIstri              Num          12
        Tunjanak               Num          12
        Pinjaman               Num          12
        Iuranwajib             Num          12
        Iuranskrela            Num          12

Hubungan antar tabel:
Tabel Karyawan  golongan  Tabel Golongan

Buatlah Form Sebagai Berikut:
   1. Form Utama yang memuat form-form dibawah ini.
   2. Form Data Karyawan (Input, Edit, Cari dan Hapus Data)
   3. Form Data Golongan (Input, Edit, Cari dan Hapus Data)
   4. Form Transaksi (Input, Edit, Cari dan Hapus Data)—berdasarkan tanggal
       transaksi dan nip karyawan.
   5. Form Cetak Laporan Data Gaji Karyawan

Kondisi & Keterangan;
   1. Pada Form transaksi terdapat kondisi khusus dimana apabila jenis kelamin laki-
       laki maka karyawan tersebut akan mendapatkan tunjangan istri dan tunjangan
       anak, sebaliknya apabila perempuan maka tidak mendapatkan tunjangan istri
       tapi mendapatkan tunjangan anak.
   2. Tunjangan istri bernilai; 150.000
   3. tunjangan anak hanya mempunyai nilai 50.000 per anak dikalikan dengan jumlah
       anak, apabila jumlah anak telah lebih dari 3 maka nilai akan sama dengan nilai
       rupiah anak dikalikan nilai maksimal (2) anak.
   4. kolom isian gaji pokok, tunjangan golongan dan iuran wajib nilainya dari tabel
       karyawan dan tabel golongan.
   5. Form Cetak Laporan Data Gaji Karyawan, data diambil dari tabel transaksi,
       dengan menampilkan semua field, dengan tambahan sebuah total Gaji :
       (gaji pokok+tunjangan golongan+tunjangan Istri+Tunjangan Anak) - (Pinjaman+Iuran
       Wajib+Iuran Sukarela)

       Tabel Golongan

            Golongan     Tunjangan Golongan           Iuran Wajib
        A               300.000                    60.000
        B               250.000                    50.000
        C               200.000                    40.000
        D               150.000                    30.000
        E               100.000                    20.000




                                                                                  Halaman 2
                                                                      © A.D. – Bandung 2005
                                         Modul Latihan [VISUAL BASIC] – Aep.Darmawan

JAWABAN LATIHAN.
Form Input Data Karyawan.




      Control      Nama Control   Properties                 Nilai Pengaturan

                                  Caption                    Input Data Karyawan
                   Form           Border Style               3 – Fixed Dialog
                                  StartUpPosition            0 – Manual

                   Label1         Caption                    NIP


                   Label2         Caption                    NAMA


                   Label3         Caption                    GOLONGAN


                   Label4         Caption                    JENIS KELAMIN


                   Label5         Caption                    TGL LAHIR


                   Label6         Caption                    STATUS


                   Label7         Caption                    GAJI POKOK


                   Label8         Caption                    JUMLAH ANAK

                                  Text                       Kosongkan
                   Text1
                                  MaxLength                  9
                                  Text                       Kosongkan
                   Text2
                                  MaxLength                  25
                                  Text                       Kosongkan
                   Combo1

                   Combo2         Text                       Kosongkan


                                                                          Halaman 3
                                                              © A.D. – Bandung 2005
                                                           Modul Latihan [VISUAL BASIC] – Aep.Darmawan



                                                    Mask                       ##-##-####
                             MaskEdBox1
                                                    Format                     dd-mm-yyyy
                                                    Text                       Kosongkan
                             Combo3

                                                    Text                       Kosongkan
                             Text3
                                                    MaxLength                  25
                                                    Text                       Kosongkan
                             Text4
                                                    MaxLength                  2

                             cmdSimpan              Caption                    Simpan


                             cmdBatal               Caption                    Batal


                             cmdTambah              Caption                    Tambah


                             cmdEdit                Caption                    Edit


                             cmdFirst               Caption                    <<


                             cmdPrev                Caption                    <


                             cmdNext                Caption                    >


                             cmdLast                Caption                    >>


                             cmdHapus               Caption                    Hapus


                             cmdKeluar              Caption                    Keluar

                                                    DataBaseName               Kosongkan
                             Data1
                                                    Recordsource               Kosongkan
                                                    DataBaseName               Kosongkan
                             Data2
                                                    Recordsource               Kosongkan



Isikan isi kode berikut dibawah ini pada properties code untuk Form;

Private Sub cmdBatal_Click()
    Kosongkan
    cmdEdit.Caption = "Edit": cmdSimpan.Enabled = True
    cmdTambah.SetFocus
End Sub
Private Sub cmdEdit_Click()
If cmdEdit.Caption = "Simpan Edit" Then
    Data1.Recordset.Edit
    Data1.Recordset.nama = Text2.Text
    Data1.Recordset.golongan = Combo1.Text
    Data1.Recordset.jkel = Combo2.Text
    Data1.Recordset.tgllahir = Format(MaskEdBox1.Text, "mm-dd-yyyy")
    Data1.Recordset.Status = Combo3.ListIndex
    Data1.Recordset.gapok = Text3.Text
    Data1.Recordset.jmlanak = Text4.Text
                                                                                            Halaman 4
                                                                                © A.D. – Bandung 2005
                                                             Modul Latihan [VISUAL BASIC] – Aep.Darmawan

  Data1.Recordset.Update

  cmdEdit.Caption = "Edit"
  cmdSimpan.Enabled = True
Else
  teks = InputBox("Isikan NIP yang akan diedit? ", "Edit")
  If teks <> "" Then
      cari = "nip = '" & teks & "'"
      Data1.Recordset.FindFirst cari
      If Data1.Recordset.NoMatch Then
         MsgBox "NIP Tdak ditemukan.."
      Else
         Tampil
         cmdSimpan.Enabled = False
         cmdEdit.Caption = "Simpan Edit"
      End If
  End If
End If
End Sub

Private Sub cmdFirst_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveFirst
      Call Tampil
      MsgBox "Data Awal..", , "Data Awal"
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdHapus_Click()
   Data1.Recordset.Delete
   Data1.Recordset.MoveLast
   Tampil
End Sub

Private Sub cmdKeluar_Click()
   Unload Me
End Sub

Private Sub cmdLast_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveLast
      Call Tampil
      MsgBox "Data Akhir..", , "Data Awal"
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdNext_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveNext
      If Not (Data1.Recordset.EOF) Then
         Call Tampil
      Else
         MsgBox "Anda Telah Sampai pada Data Akhir..", , "Data Awal"
         Data1.Recordset.MoveLast
      End If
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdPrev_Click()
                                                                                              Halaman 5
                                                                                  © A.D. – Bandung 2005
                                                        Modul Latihan [VISUAL BASIC] – Aep.Darmawan

  If Data1.Recordset.RecordCount <> 0 Then
     Data1.Recordset.MovePrevious
     If Not (Data1.Recordset.BOF) Then
        Call Tampil
     Else
        MsgBox "Anda Telah Sampai pada Data Awal..", , "Data Awal"
        Data1.Recordset.MoveFirst
     End If
  Else
     MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
  End If
End Sub

Private Sub cmdSimpan_Click()
   Data1.Recordset.AddNew
   Data1.Recordset.nip = Text1.Text
   Data1.Recordset.nama = Text2.Text
   Data1.Recordset.golongan = Combo1.Text
   Data1.Recordset.jkel = Combo2.Text
   Data1.Recordset.tgllahir = Format(MaskEdBox1.Text, "mm-dd-yyyy")
   Data1.Recordset.Status = Combo3.ListIndex
   Data1.Recordset.gapok = Text3.Text
   Data1.Recordset.jmlanak = Text4.Text
   Data1.Recordset.Update
   Data1.Recordset.MoveLast
   Tampil
End Sub

Private Sub cmdTambah_Click()
   Kosongkan: Text1.SetFocus
End Sub

Private Sub Combo1_GotFocus()
   bukaComboGol
End Sub

Private Sub Combo2_GotFocus()
   Combo2.Clear
   Combo2.AddItem "L"
   Combo2.AddItem "P"
End Sub

Private Sub Combo3_GotFocus()
   Combo3.Clear
   Combo3.AddItem "Kawin"
   Combo3.AddItem "Blm Kawin"
End Sub
Private Sub Form_Load()
   Me.Left = 0: Me.Top = 0
   Data1.DatabaseName = App.Path & "/karyawan.mdb"
   Data1.RecordSource = "SELECT * FROM tbl_karyawan"
   Data2.DatabaseName = App.Path & "/karyawan.mdb"
   Data2.RecordSource = "SELECT golongan FROM tbl_golongan"
End Sub

Public Sub bukaComboGol()
  Combo1.Clear
  Data2.Recordset.MoveFirst
  For i = 1 To Data2.Recordset.RecordCount
     Combo1.AddItem Data2.Recordset.Fields(0)
  Data2.Recordset.MoveNext
  Next i
End Sub

Public Sub Tampil()
                                                                                         Halaman 6
                                                                             © A.D. – Bandung 2005
                                                          Modul Latihan [VISUAL BASIC] – Aep.Darmawan

With Data1.Recordset
  Text1.Text = .nip
  Text2.Text = .nama
  Combo1.Text = .golongan
  Combo2.Text = .jkel
  MaskEdBox1.Text = Format(.tgllahir, "dd-mm-yyyy")
  Combo3.Text = .Status
  Text3.Text = .gapok
  Text4.Text = .jmlanak
End With
End Sub

Public Sub Kosongkan()
  Text1.Text = Clear
  Text2.Text = Clear
  Combo1_GotFocus
  Combo2_GotFocus
  MaskEdBox1.Text = Format("__-__-____", "##-##-####")
  Combo3_GotFocus
  Text3.Text = Clear
  Text4.Text = Clear
End Sub

Private Sub Form_Unload(Cancel As Integer)
   MDIForm1.StatusBar1.Panels(2).Text = "Anda berada di Form Utama "
End Sub



Form Input Golongan




         Control            Nama Control              Properties              Nilai Pengaturan

                                                      Caption                 Input Data Golongan
                            Form                      Border Style            3 – Fixed Dialog
                                                      StartUpPosition         0 – Manual

                            Label1                    Caption                 GOLONGAN


                            Label2                    Caption                 TUNJANGAN GOL


                            Label3                    Caption                 IURAN WAJIB


                                                                                           Halaman 7
                                                                               © A.D. – Bandung 2005
                                                     Modul Latihan [VISUAL BASIC] – Aep.Darmawan

                               Text1          Text                       Kosongkan


                                              MaxLength                  9
                                              Text                       Kosongkan
                               Text2
                                              MaxLength                  25
                                              Text                       Kosongkan
                               Text3
                                              MaxLength                  25

                               cmdSimpan      Caption                    Simpan


                               cmdBatal       Caption                    Batal


                               cmdTambah      Caption                    Tambah


                               cmdEdit        Caption                    Edit


                               cmdFirst       Caption                    <<


                               cmdPrev        Caption                    <


                               cmdNext        Caption                    >


                               cmdLast        Caption                    >>


                               cmdHapus       Caption                    Hapus


                               cmdKeluar      Caption                    Keluar

                                              DataBaseName               Kosongkan
                               Data1
                                              Recordsource               Kosongkan
                                              DataBaseName               Kosongkan
                               Data2
                                              Recordsource               Kosongkan

Isikan kode berikut ke properties Code untuk Form

Private Sub cmdBatal_Click()
   Kosongkan
   cmdEdit.Caption = "Edit"
   cmdSimpan.Enabled = True
   cmdTambah.SetFocus
End Sub

Private Sub cmdTambah_Click()
   Kosongkan
   Text1.SetFocus
End Sub

Private Sub cmdEdit_Click()
If cmdEdit.Caption = "Simpan Edit" Then
    Data1.Recordset.Edit
    Data1.Recordset.tunjgol = Text2.Text
    Data1.Recordset.iuranwajib = Text3.Text
    Data1.Recordset.Update

  cmdEdit.Caption = "Edit"
                                                                                      Halaman 8
                                                                          © A.D. – Bandung 2005
                                                           Modul Latihan [VISUAL BASIC] – Aep.Darmawan

  cmdSimpan.Enabled = True
Else
  teks = InputBox("Isikan Golongan yang akan diedit? ", "Edit")
  If teks <> "" Then
      cari = "golongan = '" & teks & "'"
      Data1.Recordset.FindFirst cari
      If Data1.Recordset.NoMatch Then
         MsgBox "Golongan Tdak ditemukan.."
      Else
         Tampil
         cmdSimpan.Enabled = False
         cmdEdit.Caption = "Simpan Edit"
      End If
  End If
End If

End Sub

Private Sub Command1_Click()
   Data1.Recordset.Delete
   Data1.Recordset.MoveLast
   Tampil
End Sub

Private Sub Form_Load()
   Me.Left = 0: Me.Top = 0
   Data1.DatabaseName = App.Path & "/karyawan.mdb"
   Data1.RecordSource = "SELECT * FROM tbl_golongan"
End Sub

Private Sub cmdFirst_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveFirst
      Call Tampil
      MsgBox "Data Awal..", , "Data Awal"
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdKeluar_Click()
   Unload Me
End Sub

Private Sub cmdLast_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveLast
      Call Tampil
      MsgBox "Data Akhir..", , "Data Awal"
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdNext_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveNext
      If Not (Data1.Recordset.EOF) Then
         Call Tampil
      Else
         MsgBox "Anda Telah Sampai pada Data Akhir..", , "Data Awal"
         Data1.Recordset.MoveLast
      End If
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
                                                                                            Halaman 9
                                                                                © A.D. – Bandung 2005
                                                         Modul Latihan [VISUAL BASIC] – Aep.Darmawan

  End If
End Sub

Private Sub cmdPrev_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MovePrevious
      If Not (Data1.Recordset.BOF) Then
         Call Tampil
      Else
         MsgBox "Anda Telah Sampai pada Data Awal..", , "Data Awal"
         Data1.Recordset.MoveFirst
      End If
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdSimpan_Click()
   If Text1.Text = Empty Then
      Text1.SetFocus
      Exit Sub
   End If

  cari = "golongan = '" & Text1.Text & "'"
  Data1.Recordset.FindFirst cari

  If Data1.Recordset.NoMatch Then
     Data1.Recordset.AddNew
     Data1.Recordset.golongan = Text1.Text
     Data1.Recordset.tunjgol = Text2.Text
     Data1.Recordset.iuranwajib = Text3.Text
     Data1.Recordset.Update
     Data1.Recordset.MoveLast
     Tampil
  Else
     MsgBox "GOLONGAN Sudah Ada", vbExclamation, "Pesan Error"
     Text1.SetFocus
  End If

End Sub

Public Sub Tampil()
With Data1.Recordset
  Text1.Text = .golongan
  Text2.Text = .tunjgol
  Text3.Text = .iuranwajib
End With
End Sub

Public Sub Kosongkan()
  Text1.Text = Clear
  Text2.Text = Clear
  Text3.Text = Clear
End Sub

Private Sub Form_Unload(Cancel As Integer)
   MDIForm1.StatusBar1.Panels(2).Text = "Anda berada di Form Utama "
End Sub




                                                                                         Halaman 10
                                                                              © A.D. – Bandung 2005
                                       Modul Latihan [VISUAL BASIC] – Aep.Darmawan

Form Transaksi




      Control    Nama Control   Properties                 Nilai Pengaturan

                                Caption                    Input Data Transaksi
                 Form           Border Style               3 – Fixed Dialog
                                StartUpPosition            0 – Manual

                 Label1         Caption                    TGL


                 Label2         Caption                    NIP


                 Label3         Caption                    GOLONGAN


                 Label4         Caption                    GAJI POKOK


                 Label5         Caption                    TUNJANGAN GOL


                 Label6         Caption                    TUNJANGAN ISTRI


                 Label7         Caption                    TUNJANGAN ANAK


                 Label8         Caption                    PINJAMAN


                 Label9         Caption                    IURAN WAJIB


                 Label10        Caption                    IURAN SUKARELA

                                Mask                       ##-##-####
                 MaskEdBox1
                                Format                     dd-mm-yyyy
                                Text                       Kosongkan
                 Text1
                                MaxLength                  9

                                                                       Halaman 11
                                                            © A.D. – Bandung 2005
                                                   Modul Latihan [VISUAL BASIC] – Aep.Darmawan

                                            Text                       Kosongkan
                          Text2
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text3
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text4
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text5
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text6
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text7
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text8
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text9
                                            MaxLength                  0
                                            Text                       Kosongkan
                          Text10
                                            MaxLength                  0

                          cmdSimpan         Caption                    Simpan


                          cmdBatal          Caption                    Batal


                          cmdTambah         Caption                    Tambah


                          cmdEdit           Caption                    Edit


                          cmdFirst          Caption                    <<


                          cmdPrev           Caption                    <


                          cmdNext           Caption                    >


                          cmdLast           Caption                    >>


                          cmdHapus          Caption                    Hapus


                          cmdKeluar         Caption                    Keluar

                                            DataBaseName               Kosongkan
                          Data1
                                            Recordsource               Kosongkan
                                            DataBaseName               Kosongkan
                          Data2
                                            Recordsource               Kosongkan

Isikan kode berikut ke properties Code untuk Form

Private Sub cmdBatal_Click()
   Kosongkan: cmdTambah.SetFocus
End Sub

                                                                                   Halaman 12
                                                                        © A.D. – Bandung 2005
                                                         Modul Latihan [VISUAL BASIC] – Aep.Darmawan

Private Sub cmdSimpan_Click()
   Data1.Recordset.AddNew
   Data1.Recordset.tanggal = MaskEdBox1.Text
   Data1.Recordset.nip = Text1.Text
   Data1.Recordset.nama = Text2.Text
   Data1.Recordset.golongan = Text3.Text
   Data1.Recordset.gapok = Text4.Text
   Data1.Recordset.tunjgol = Text5.Text
   Data1.Recordset.tunjistri = Text6.Text
   Data1.Recordset.tunjanak = Text7.Text
   Data1.Recordset.pinjaman = Text8.Text
   Data1.Recordset.iuranwajib = Text9.Text
   Data1.Recordset.iuransukarela = Text10.Text
   Data1.Recordset.Update
   Data1.Recordset.MoveLast
   Tampil
End Sub

Private Sub cmdTambah_Click()
   Kosongkan
   MaskEdBox1.SetFocus
End Sub

Private Sub Command1_Click()
   Data1.Recordset.Delete
   Data1.Recordset.MoveLast
   Tampil
End Sub

Private Sub Form_Load()
   Me.Left = 0: Me.Top = 0
   Data1.DatabaseName = App.Path & "/karyawan.mdb"
   Data1.RecordSource = "SELECT * FROM tbl_transaksi"
   Data2.DatabaseName = App.Path & "/karyawan.mdb"
   Data2.RecordSource = "SELECT * FROM tbl_karyawan,tbl_golongan WHERE
tbl_karyawan.golongan=tbl_golongan.golongan"
End Sub

Private Sub cmdFirst_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveFirst
      Call Tampil
      MsgBox "Data Awal..", , "Data Awal"
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdKeluar_Click()
   Unload Me
End Sub

Private Sub cmdLast_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveLast
      Call Tampil
      MsgBox "Data Akhir..", , "Data Awal"
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Private Sub cmdNext_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MoveNext
                                                                                         Halaman 13
                                                                              © A.D. – Bandung 2005
                                                         Modul Latihan [VISUAL BASIC] – Aep.Darmawan

    If Not (Data1.Recordset.EOF) Then
       Call Tampil
    Else
       MsgBox "Anda Telah Sampai pada Data Akhir..", , "Data Awal"
       Data1.Recordset.MoveLast
    End If
  Else
    MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
  End If
End Sub

Private Sub cmdPrev_Click()
   If Data1.Recordset.RecordCount <> 0 Then
      Data1.Recordset.MovePrevious
      If Not (Data1.Recordset.BOF) Then
         Call Tampil
      Else
         MsgBox "Anda Telah Sampai pada Data Awal..", , "Data Awal"
         Data1.Recordset.MoveFirst
      End If
   Else
      MsgBox "Data Masih Kosong !", vbInformation, "Data Kosong"
   End If
End Sub

Public Sub Tampil()
With Data1.Recordset
  MaskEdBox1.Text = Format(.tanggal, "dd-mm-yyyy")
  Text1.Text = .nip
  Text2.Text = .nama
  Text3.Text = .golongan
  Text4.Text = .gapok
  Text5.Text = .tunjgol
  Text6.Text = .tunjistri
  Text7.Text = .tunjanak
  Text8.Text = .pinjaman
  Text9.Text = .iuranwajib
  Text10.Text = .iuransukarela
End With
End Sub

Public Sub Kosongkan()
  MaskEdBox1.Text = Format("__-__-____", "##-##-####")
  Text1.Text = Clear
  Text2.Text = Clear
  Text3.Text = Clear
  Text4.Text = Clear
  Text5.Text = Clear
  Text6.Text = Clear
  Text7.Text = Clear
  Text8.Text = Clear
  Text9.Text = Clear
  Text10.Text = Clear
End Sub

Private Sub Form_Unload(Cancel As Integer)
   MDIForm1.StatusBar1.Panels(2).Text = "Anda berada di Form Utama "
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
   If Text1.Text = Empty Then
      Text1.SetFocus
      Exit Sub
   End If
                                                                                         Halaman 14
                                                                              © A.D. – Bandung 2005
                                                         Modul Latihan [VISUAL BASIC] – Aep.Darmawan

  tmpTgl = MaskEdBox1.Text
  tmpText1 = Text1.Text
  cari = "tanggal = #" & MaskEdBox1.Text & "# AND nip = '" & Text1.Text & "'"
  Data1.Recordset.FindFirst cari
  If Data1.Recordset.NoMatch Then
     Data2.Recordset.FindFirst ("nip= '" & Text1.Text & "'")
     If Data2.Recordset.NoMatch Then
        MsgBox "NIP tidak ditemukan"
     Else
        Text2.Text = Data2.Recordset.Fields(1) 'nama
        Text3.Text = Data2.Recordset.Fields(2) 'golongan
        Text4.Text = Data2.Recordset.Fields(6) 'gapok
        Text5.Text = Data2.Recordset.Fields(9) 'tunjgol
        If Data2.Recordset.Fields(5) = 0 Then Text6.Text = 150000 Else Text6.Text = 0 'status
        If Data2.Recordset.Fields(6) = 0 Then 'jmlanak
           Text7.Text = 0
        ElseIf Data2.Recordset.Fields(6) > 0 And Data2.Recordset.Fields(6) < 3 Then 'jmlanak
           Text7.Text = Data2.Recordset.Fields(6) * 50000
        Else
           Text7.Text = 2 * 50000
        End If
        Text9.Text = Data2.Recordset.Fields(10) 'iuranwajib
        Text8.SetFocus
     End If
  Else
     Tampil
  End If
End If
End Sub

Form Data Report

Lakukan dengan membuat DataEnvironment seperti telah dipelajari pada modul Report,
kemudian untuk langkah koneksi ke tabel pada bagian Source of data pilihlah AQL
statement, kemudian isikan syntak SQL dibawah ini;
SELECT tanggal, nip, nama, golongan, gapok, tunjgol, tunjistri, tunjanak, pinjaman,
iuranwajib,    iuransukarela,      (gapok+tunjgol+tunjistri+tunjanak)     AS       jml1,
(pinjaman+iuranwajib+iuransukarela)   AS      jml2, ((gapok+tunjgol+tunjistri+tunjanak)-
(pinjaman+iuranwajib+iuransukarela)) AS total FROM tbl_transaksi
Dan lakukan langkah pembuatan Datareport serta pengisian label dan textbox sesuai
dengan yang dipelajari pada modul Report, susun rapi isi dari report tersebut sehingga
tampak seperti gambar dibawah ini;




                                                                                            Halaman 15
                                                                                 © A.D. – Bandung 2005
                                                          Modul Latihan [VISUAL BASIC] – Aep.Darmawan

Form Utama

Buatlah sebuah form MDI, dan set semua form diatas pada properties nilai MDIChild
menjadi True
Kemudian susun menu seperti dibawah ini
       File
             Input data Golongan
             Input Data Karyawan
             ----------------------------
             Tutup Form Aktif
             ----------------------------
             Keluar
       Transaksi
             Input Transaksi
       Laporan
             Laporan Gaji Karyawan

Kemudian isikan kode berikut dibawah ini kedalam properties Code untuk Form MDI

Dim porm
Private Sub MDIForm_Load()
   Me.Caption = "Data Karyawan ___ :::___ Latihan Pemrograman Visual Basic [LPKA Wahana Cendekia]"
   StatusBar1.Panels(1).Text = "Tanggal : " & Format(Now(), "dd-mm-yyyy")
End Sub

Private Sub mnGol_Click()
   Form2.Show
   porm = 2: StatusBar1.Panels(2).Text = "Anda berada di Form Input Data Golongan "
End Sub

Private Sub mninputtrans_Click()
   Form3.Show
   porm = 3: StatusBar1.Panels(2).Text = "Anda berada di Form Input Transaksi "
End Sub

Private Sub mnkar_Click()
   Form1.Show
   porm = 1: StatusBar1.Panels(2).Text = "Anda berada di Form Input Data Karyawan "
End Sub

Private Sub mnkeluar_Click()
   End
End Sub

Private Sub mnlapgaji_Click()
   DataReport1.Show
   porm = 4: StatusBar1.Panels(2).Text = "Anda berada di Form Laporan "
End Sub
Private Sub mntutup_Click()
   If porm = 1 Then
       Unload Form1
   ElseIf porm = 2 Then
       Unload Form2
   ElseIf porm = 3 Then
       Unload Form3
   ElseIf porm = 4 Then
       Unload DataReport1
   End If
End Sub


                                                                                             Halaman 16
                                                                                  © A.D. – Bandung 2005

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:5954
posted:10/18/2010
language:Indonesian
pages:16