MODULAR Pemusatan fungsi – fungsi atau sub – sub, dengan tujuan efisiensi Konsep Modular :
Contoh :
Melakukan operasi matematika dengan nilai Variabel 1 = 4 dan Variabel 2 = 2 Cara Konvensional Form Tambah (Private) •Function Tambah ( 4 + 2 = 3)
Form Kurang (Private) •Function Kurang ( 4 - 2 = 2)
Form Kali (Private) •Function Kali ( 4 * 2 = 8)
Form Bahagi (Private) Form Tambah Kurang Kali Bahagi (Private)
•Function Bahagi ( 4 / 2 = 2)
Form Pangkat (Private) •Function Pangkat ( 4^2 = 16)
•Function •Function •Function •Function •Function
Tambah ( 1 + 2 = 3) Kurang ( 4 - 2 = 2) Kali ( 4 * 2 = 8) Bahagi ( 4 / 2 = 2) Pangkat ( 4^2 = 16)
Modul Matematika (Public) •Function Tambah ( 1 + 2 = 3) •Function Kurang ( 4 - 2 = 2) •Function Kali ( 4 * 2 = 8) •Function Bahagi ( 4 / 2 = 2) •Function Pangkat ( 4^2 = 16) Form Tambah (Private) •Call Tambah (3)
Form Kurang (Private) •Call Kurang (2)
Form Kali (Private) •Call Kali (8)
Form Bahagi (Private) •Call Bahagi (2)
Form Pangkat (Private) •Call Pangkat (16)
Form Tambah Kurang Kali Bahagi (Private) •Call Tambah (3) •Call Kurang (2) •Call Kali (8) •Call Bahagi (2) •Call Pangkat (16)
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
Konsep Modular
1
KONSEP MODULAR UMUM – UMUM Tambahkan komponen sebagai berikut : Modul (name : mdlMatematika) Public Var1 As Double Public Var2 As Double Public hTambah, hKurang, hKali, hBahagi As Double Public Function Tambah() hTambah = Var1 + Var2 End Function Public Function Kurang() hKurang = Var1 - Var2 End Function Public Function Kali() hKali = Var1 * Var2 End Function Public Function Bahagi() hBahagi = Var1 / Var2 End Function
Catatan :
No
Jenis Kontrol
Name
Property Lainnya
1
PictureBox
pbChat
Align = 4 - Align Right, Visible = False
2
ListBox
lsChat
3
CommandButton
cmdClient
Caption = Tambah Client
4
CommandButton
cmdBersih
Caption = Bersihkan List
5
MenuEditor
mnMatematika
Matematika
6
MenuEditor
mnTambah
...
Tambah
7
MenuEditor
mnKurang
...
Kurang
8
MenuEditor
mnKali
...
Kali
9
MenuEditor
mnBahagi
...
Bahagi
10
MenuEditor
mnx
...
-
11
MenuEditor
mnTKKB
...
Tambah Kurang Kali Bahagi
12
MenuEditor
mnString
String
13
MenuEditor
mnChat
...
Chat Server
14
MenuEditor
mnTutupChat
...
Tutup Server
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
MDI Form (nama : mdiUtama, Caption = Test Modul, WindowState = 2 - Maximized)
2
Name : frmTambah (Caption Tambah, BorderStyle = 1 - Fixed Single, MDIChild = True) No Jenis Kontrol Name Property Lainnya 1 TextBox txt1 2 TextBox txt2 3 TextBox txtHasil 4 CommandButton cmdTambah Caption = Tambah (+)
Name : frmKali (Caption : Kali, BorderStyle = 1 - Fixed Single, MDIChild = True) No Jenis Kontrol Name Property Lainnya 1 TextBox txt1 2 TextBox txt2 3 TextBox txtHasil 4 CommandButton cmdKali Caption = Kali (*)
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
Name : frmKurang (Caption: Kurang, BorderStyle = 1 - Fixed Single, MDIChild = True) No Jenis Kontrol Name Property Lainnya 1 TextBox txt1 2 TextBox txt2 3 TextBox txtHasil 4 CommandButton cmdKurang Caption = Kurang (-)
3
Name : frmBahagi (Caption : Bahagi, BorderStyle = 1 - Fixed Single, MDIChild = True) No Jenis Kontrol Name Property Lainnya 1 TextBox txt1 2 TextBox txt2 3 TextBox txtHasil 4 CommandButton cmdBahagi Caption = Bahagi (/)
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
Name : frmTambahKurangKaliBahagi (Caption : Tambah Kurang Kali Bahagi, BorderStyle = 1 - Fixed Single, MDIChild = True) No Jenis Kontrol Name Property Lainnya 1 TextBox txt1 2 TextBox txt2 3 TextBox txtTambah 4 TextBox txtKurang 5 TextBox txtKali 6 TextBox txtBahagi 7 CommanButton cmdHitung Caption = Hitung
4
-
Syntax di Form : mdiUtama
Double Click Pada, kemudian ketikan syntax berikut : mnTambah (Event : Click()) Private Sub mnTambah_Click() frmTambah.Show End Sub
Catatan : mnKurang (Event : Click()) Private Sub mnKurang_Click() frmKurang.Show End Sub
Catatan : mnKali(Event : Click()) Private Sub mnKali_Click() frmKali.Show End Sub
Catatan : mnBahagi (Event : Click()) Private Sub mnBahagi_Click() frmTambah.Show End Sub
Catatan : mnTKKB (Event : Click()) Private Sub mnTKKB_Click() frmTambahKurangKaliBahagi.Show End Sub
-
Syntax di Form : frmTambah
Double Click Pada, kemudian ketikan pada : cmdTambah (Event : Click()) Private Sub cmdTambah_Click() Var1 = Val(txt1.Text) Var2 = Val(txt2.Text) Call Tambah txtHasil.Text = hTambah End Sub
Catatan :
-
Syntax di Form : frmKurang
Double Click Pada, kemudian ketikan pada : cmdKurang (Event : Click()) Private Sub cmdKurang_Click() Var1 = Val(txt1.Text) Var2 = Val(txt2.Text) Call Kurang txtHasil.Text = hKurang End Sub
Catatan :
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
Catatan :
5
-
Syntax di Form : frmKali
Double Click Pada, kemudian ketikan pada : cmdKali (Event : Click()) Private Sub cmdKali_Click() Var1 = Val(txt1.Text) Var2 = Val(txt2.Text) Call Kali txtHasil.Text = hKali End Sub
Catatan :
-
Syntax di Form : frmBahagi
Double Click Pada, kemudian ketikan pada : cmdBahagi (Event : Click()) Private Sub cmdBahagi_Click() Var1 = Val(txt1.Text) Var2 = Val(txt2.Text) Call Bahagi txtHasil.Text = hBahagi End Sub
Catatan :
-
Syntax di Form : frmTambahKurangKaliBahagi
Private Sub cmdHitung_Click() Var1 = Val(txt1.Text) Var2 = Val(txt2.Text) Call Tambah Call Kurang Call Kali Call Bahagi txtTambah.Text = hTambah txtKurang.Text = hKurang txtKali.Text = hKali txtBahagi.Text = hBahagi End Sub
Catatan :
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
Double Click Pada, kemudian ketikan pada : cmdHitung (Event : Click())
6
KONSEP MODULAR UMUM – KHUSUS Kemudian dalam proyek tadi, Tambahkan komponen sebagai berikut :
Modul (name : mdlString) Public BufferPesan As String Public namaUser As String Public Function KirimPesan() mdiUtama.lstChat.AddItem namaUser & " : " & BufferPesan End Function
Catatan :
Name : frmSetClient (Caption: User Baru, BorderStyle = 1 - Fixed Single, MDIChild = True) No Jenis Kontrol Name Property Lainnya 1 TextBox txtUser MaxLen = 5 2 Command Button cmdDaftar Caption = Daftar
Modul (name : mdlBuatClient) Public ClientBaru As frmClient Public User As String Public Function BuatClient() Set ClientBaru = New frmClient Load ClientBaru With ClientBaru .Caption = User .Show End With End Function
Catatan :
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
Name : frmClient (Caption: Client, BorderStyle = 1 - Fixed Single, MDIChild = True) No Jenis Kontrol Name Property Lainnya 1 TextBox txtPesan MaxLen = 30 2 Command Button cmdKirim Caption = Kirim
7
-
Syntax di Form : frmSetClient
Double Click Pada, kemudian ketikan pada : cmdDaftar(Event : Click()) Private Sub cmdDaftar_Click() User = txtUser.Text Call BuatClient Unload Me End Sub
Catatan :
-
Syntax di Form : frmClient
Double Click Pada, kemudian ketikan pada : cmdKirim(Event : Click()) Private Sub cmdKirim_Click() namaUser = Me.Caption BufferPesan = txtPesan.Text KirimPesan txtPesan.Text = "" txtPesan.SetFocus End Sub
Catatan :
-
Syntax di Form : mdiUtama
Double Click Pada, kemudian ketikan pada : cmdClient(Event : Click()) Private Sub cmdClient_Click() frmSetClient.Show End Sub
cmdBersih(Event : Click()) Private Sub cmdBersih_Click() lstChat.Clear End Sub
Catatan :
Microsoft Visual Basic 6 : PENERAPAN KONSEP MODULAR arifintindi
Catatan :
8