Pemrograman berorientasi objek ii 04 prosedur dan fungsi

Preview:

DESCRIPTION

fungsi dan prosedur dalam visual basic

Citation preview

PROSEDUR DAN FUNGSI

Pemrograman Berorientasi Objek IIPertemuan – 5

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

1

Prosedur dan Fungsi

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

• Sub• Private sub

• Fungsi– Cint– Csng– kata kunci:

• Function • Private function

2

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

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

Prosedur sederhana

5

cmdUtang

Menambahkan prosedur

6Project30 sub

Koding prosedur

7

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

Menambahkan fungsi

9Project31 fungsi

Koding project31

10

Module

• Fungsi dan prosedur bisa dikelompokkan dalam sebuah module

11

Prosedur Genap Ganjil

12

Modul genapganjil

• Tambahkan procedure:

13

Project module

14

frmGenapGanjil

txtAngka

cmdTutup

cmdBersihcmdCek

Koding project32

15

Tambahkan function di module

16

cmdCekfungsi

17

cmdCekFungsi

Tugas

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

• Jadikan project-project tersebut menjadi project32-project46

• Kumpulkan dalam CD

18

MDI DAN MENU

19

Buat project standard.exe baru

• Tambahkan MDI Form

20

Startup object=MDIForm1

21

Tambahkan menu

22

mnuProsedur dan mnuUtang

23

Sumber

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

• QUE

24

Recommended