24
PROSEDUR DAN FUNGSI Pemrograman Berorientasi Objek II Pertemuan – 5 Edri Yunizal, S.Kom., M.T. Lita Sari Muchlis, M.Kom. 1

Pemrograman berorientasi objek ii 04 prosedur dan fungsi

Embed Size (px)

DESCRIPTION

fungsi dan prosedur dalam visual basic

Citation preview

Page 1: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

PROSEDUR DAN FUNGSI

Pemrograman Berorientasi Objek IIPertemuan – 5

Edri Yunizal, S.Kom., M.T.Lita Sari Muchlis, M.Kom.

1

Page 2: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Prosedur dan Fungsi

• Prosedur– Load()– Click()– Kata kunci

• Sub• Private sub

• Fungsi– Cint– Csng– kata kunci:

• Function • Private function

2

Page 3: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

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

Page 4: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

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

block. 4

Page 5: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Prosedur sederhana

5

cmdUtang

Page 6: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Menambahkan prosedur

6Project30 sub

Page 7: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Koding prosedur

7

Page 8: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

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

Page 9: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Menambahkan fungsi

9Project31 fungsi

Page 10: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Koding project31

10

Page 11: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Module

• Fungsi dan prosedur bisa dikelompokkan dalam sebuah module

11

Page 12: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Prosedur Genap Ganjil

12

Page 13: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Modul genapganjil

• Tambahkan procedure:

13

Page 14: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Project module

14

frmGenapGanjil

txtAngka

cmdTutup

cmdBersihcmdCek

Page 15: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Koding project32

15

Page 16: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Tambahkan function di module

16

Page 17: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

cmdCekfungsi

17

cmdCekFungsi

Page 18: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Tugas

• Buat Project15-project29 dalam bentuk fungsi dan prosedur dengan menggunakan module

• Jadikan project-project tersebut menjadi project32-project46

• Kumpulkan dalam CD

18

Page 19: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

MDI DAN MENU

19

Page 20: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Buat project standard.exe baru

• Tambahkan MDI Form

20

Page 21: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Startup object=MDIForm1

21

Page 22: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Tambahkan menu

22

Page 23: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

mnuProsedur dan mnuUtang

23

Page 24: Pemrograman berorientasi objek ii   04 prosedur dan fungsi

Sumber

• H.S., Suryadi., Sumin, Agus. (1997). Pengantar Algoritma dan Pemrograman: Teknik Diagram Alur dan Bahasa Basic Dasar. Jakarta: Universitas Gunadarma

• QUE

24