Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

1 Pertemuan 8 Collection Matakuliah: M0462/Programming I Tahun: 2005 Versi: >

Presentasi serupa


Presentasi berjudul: "1 Pertemuan 8 Collection Matakuliah: M0462/Programming I Tahun: 2005 Versi: >"— Transcript presentasi:

1 1 Pertemuan 8 Collection Matakuliah: M0462/Programming I Tahun: 2005 Versi: >

2 2 Learning Outcomes Pada akhir pertemuan ini, diharapkan mahasiswa akan mampu : Mahasiswa dapat Menjelaskan konsep dari collection

3 3 Outline Materi Form Collection Control Collection Perulangan dalam Collection Add and Remove Method Count, Item, Index Property Membangun Collection dengan Class Module

4 4 Collection Collection adalah sekumpulan dari object yang mempunyai struktur yang sama. Kelebihan Collection adalah kita bisa membuat array object. Secara umum Collection mempunyai 4 buah property dan method, yaitu Count, Item, Add dan Remove

5 5 Collection Contoh : colMyCollection.Item(n) ‘ atau collMyCollection(n) (n adalah nomor dari item yang ada, untuk pemakaian lebih lanjut bisa menggunakan For Each) Form Collection dan Controls Collection adalah collection yang sudah built-in dalam VB –Form Collection adalah sebuah Collection dimana setiap elemennya mewakili setiap form dalam sebuah aplikasi –Control Collection berisi semua object control di dalam sebuah form

6 6 Cara Mengakses Collection Cara mengakses Collection sama dengan Array For n=0 to colMyCollection.Count-1 colMyCollection(n).Visible= False Next n Menggunakan For Each For Each objItem in colMyCollection objItem.Visible= False Next objItem

7 7 Membuat Collection Untuk membangun sebuah Collection kita perlu deklarasi variable menggunakan tipe data Collection Dim colMyCollection as New Collection Collection yang dibangun tersebut otomatis akan mempunyai 4 properties dan method : Count property - jumlah item dalam collection Item property - menunjuk suatu object dalam Collection Add method - menempatkan object dalam Collection Remove method - menghapus object dalam Collection

8 8 Membangun Collection dengan Class Module Lebih lanjut jika kita ingin mengembangkan Collection yang sudah kita buat, kita perlu membuat Collection kita sebagai Class Module. Di dalam Class module ini kita bisa menambahkan property atau method baru sera memodifikasi property dan method yang sudah ada Langkah awal kita harus buat satu class Module yang berisi data tunggal (contoh : clsEmployee), serta data Collection (contoh : clsColEmployee) Di dalam Class Module yang kita buat kita deklarasikan Collection beserta dengan property dan method yang kita inginkan

9 9 Membangun Collection dengan Class Module Class module : clsEmployee Dim xNama As String Public Property Get Nama() As Variant Nama = xNama End Property Public Property Let Nama(ByVal vNewValue As Variant) xNama = vNewValue End Property

10 10 Class Module : clsColEmployee Private colEmployee as New Collection Sub Tambah(objEmp as Object, Optional Key, Optional Before,Optional After) colEmployee.Add objEmp, Key, Before, After End Sub Sub Hapus colEmployee.Remove Index End Sub

11 11 Function Item(Index) as Object Set Item = colEmployee.Item(Index) End Function Property Get Jumlah() as Integer Jumlah = colEmployee.Count End Property

12 12 Sedangkan cara menggunakan Class Module yang sudah kita buat, tinggal deklarasi dari form aplikasi Dim objColEmployee As clsColEmployee Dim objEmployee As clsEmployee Private Sub Form_Load() Set objColEmployee = New clsColEmployee Set objEmployee = New clsEmployee objEmployee.Nama = "Budi" objColEmployee.Tambah objNama objColEmployee.Item (1) MsgBox objColEmployee.Jumlah objColEmployee.Hapus 0 End Sub

13 13 Referensi VBScript 5.5.chm

14 14 SELESAI


Download ppt "1 Pertemuan 8 Collection Matakuliah: M0462/Programming I Tahun: 2005 Versi: >"

Presentasi serupa


Iklan oleh Google