2. Prosedur dan Fungsi
• Prosedur
– Load()
– Click()
– Kata kunci
• Sub
• Private sub
• Fungsi
– Cint
– Csng
– kata kunci:
• Function
• Private function 2
3. Pemrograman prosedural dg VB6
• Buat kumpulan perintah yang diberi sebuah
nama
• Nama kumpulan perintah itu bisa dieksekusi
• Caranya:
– Buat kode yang diiinginkan
– Buat blok kodenya,
• Prosedur: Sub..end sub
• Fungsi: Function... End function
– Panggil nama blok kode tersebut
• Fungsi: mengembalikan nilai, prosedur: tidak 3
4. Prosedur
• A sub is a procedure that executes the lines of code within its
block but doesn't return a value. The syntax for a simple sub is
as follows:
[Private|Public] Sub SubName(parameter)
.....lines of code
End Sub
• In this syntax
– [Private|Public] are the optional Visual Basic keywords that define the
scope of the sub.
– Sub is the Visual Basic keyword that denotes the type of procedure.
– Parameter: nilai yang dikirimkan (kalau ada)
– SubName is the name that you assign to your sub.
– End Sub are the Visual Basic keywords that denote the end of a code 4
8. Fungsi
• A function is a procedure that executes lines of code and returns a value. The
syntax for declaring a simple function is as follows:
[Private|Public] Function FunctionName(parameter) As DataType
...lines of code
FunctionName = ReturnValue
End Function
• In this syntax
– Private|Public are the optional Visual Basic keywords that define the scope of the
function.
– Function is the Visual Basic keyword that denotes the procedure is a function.
– FunctionName is the name that you assign to your function.
– Parameter: nilai yang dikirimkan (kalau ada)
– As is the Visual Basic keyword that denotes a data type assignment.
– DataType is the data type of the value that the function will return.
– ReturnValue is the value that you pass back from the function by assigning it to the
function's name. (This is very important!)
– End Function are the Visual Basic keywords that denote the end of a code block. 8
18. Tugas
• Buat Project15-project29 dalam bentuk fungsi
dan prosedur dengan menggunakan module
• Jadikan project-project tersebut menjadi
project32-project46
• Kumpulkan dalam CD
18
24. Sumber
• H.S., Suryadi., Sumin, Agus. (1997). Pengantar
Algoritma dan Pemrograman: Teknik Diagram
Alur dan Bahasa Basic Dasar. Jakarta:
Universitas Gunadarma
• QUE
24