API _ Class Module

27
BAB 2 CLASS MODULE Dalam bab ini akan dibahas mengenai pengenalan Class Module, fungsi Class Module, dan pembuatan Class Module beserta cara pengaplikasiannya ke sebuah program dalam Visual Basic 6.0. Setelah mempelajari bab ini, pembaca diharapkan mampu : Mengetahui pengertian dan fungsi Class Module. Mengetahui pembuatan Class Module dalam VB 6. Mengetahui pengaplikasian Class Module pada VB 6. BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27 Pendahuluan Tujuan BAB 2 2.1. PENGENALAN CLASS MODULE

Transcript of API _ Class Module

Page 1: API _ Class Module

BAB 2

CLASS MODULE

Dalam bab ini akan dibahas mengenai pengenalan Class

Module, fungsi Class Module, dan pembuatan Class Module beserta

cara pengaplikasiannya ke sebuah program dalam Visual Basic 6.0.

Setelah mempelajari bab ini, pembaca diharapkan mampu :

Mengetahui pengertian dan fungsi Class Module.

Mengetahui pembuatan Class Module dalam VB 6.

Mengetahui pengaplikasian Class Module pada VB 6.

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Pendahuluan

Tujuan

BAB 22.1. PENGENALAN CLASS MODULE

Page 2: API _ Class Module

Buatlah 5 source code berkaitan dengan bangun datar dan 5 source

code berkaitan dengan bangun ruang ! Gunakan class module untuk

menyelesaikannya. Jadikan 1 menu dengan menggunakan menu

editor.

Buka VB 6 kemudian pilih Standar EXE. Buat sebuah class module

dengan nama Class1. Di dalam class module ini berisi rumus

bangun datar dan bangun ruang. Bangun datar yang digunakan,

antara lain pesegi, persegi panjang, segitiga, lingkaran, jajargenjang,

belahketupat, dan layang-layang. Bangun ruang yang digunakan

yaitu kubus, balok, kerucut, limas segiempat, tabung, dan bola.

Berikut source codenya :

Public Function lpersegi(ByVal S As Double) As Double

lpersegi = S * S

End Function

Public Function kpersegi(ByVal S As Double) As Double

kpersegi = S + S

End Function

Public Function lpanjang(ByVal p As Double, l As Double) As

Double

lpanjang = p * l

End Function

Public Function kpanjang(ByVal p As Double, l As Double) As

Double

kpanjang = 2 * (p + l)

End Function

Public Function lsegitiga(ByVal a As Double, t As Double) As

Double

lsegitiga = 0.5 * (a * t)

End Function

Public Function vkubus(ByVal S As Double) As Double

vkubus = S ^ 3

End Function

Public Function vbalok(ByVal p As Double, l As Double, t As

Double) As Double

vbalok = p * l * t

End Function

Public Function llingkaran(ByVal r As Double) As Double

Dim phi As Double

phi = 3.14

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

SOAL LATIHAN

JAWABAN

Page 3: API _ Class Module

llingkaran = phi * (r * r)

End Function

Public Function ljg(ByVal a As Double, t As Double) As Double

ljg = a * t

End Function

Public Function lbkll(ByVal d1 As Double, d2 As Double) As

Double

lbkll = 0.5 * d1 * d2

End Function

Public Function vkerucut(ByVal r As Double, t As Double) As

Double

Dim phi As Double

phi = 3.14

vkerucut = phi * (r ^ 2) * t * (1 / 3)

End Function

Public Function lkerucut(ByVal r As Double, S As Double) As

Double

Dim phi As Double

phi = 3.14

lkerucut = (phi * r) * (S * r)

End Function

Public Function vlimas(ByVal p As Double, l As Double, t As

Double) As Double

vlimas = p * l * t * (1 / 3)

End Function

Public Function llimas(ByVal p As Double, l As Double, t As

Double) As Double

llimas = ((p + l) * t) + (p * l)

End Function

Public Function vtabung(ByVal r As Double, t As Double) As

Double

Dim phi As Double

phi = 3.14

vtabung = phi * (r ^ 2) * t

End Function

Public Function ltabung(ByVal r As Double, t As Double) As

Double

Dim phi As Double

phi = 3.14

ltabung = (phi * (r * 2)) * (t * r)

End Function

Public Function vbola(ByVal r As Double, t As Double) As Double

Dim phi As Double

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 4: API _ Class Module

phi = 3.14

vbola = (phi * r * (t ^ 3)) * (4 / 3)

End Function

Public Function lbola(ByVal r As Double, t As Double) As Double

Dim phi As Double

phi = 3.14

lbola = 4 * (phi * (r ^ 2))

End Function

Buat 13 form yang akan digunakan untuk masing-masing bangun

datar dan bangun ruang.

Form1 :

Pertama buatlah Form1 untuk bangun datar persegi dan simpan

dengan nama bdPersegi.frm. Di dalam Form1, buat object sebagai

berikut :

a. Label1, Name = Label1; Caption = PERSEGI

b. Label2, Name = Label2; Caption = SISI

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = -

e. TextBox1, Name = Text1; Caption = -

f. CommandButton1, Name = Command1; Caption = LUAS

g. CommandButton2, Name = Command1; Caption = KELILING

h. CommandButton3, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Perhatikan bahwa class module yaitu Class1 akan muncul ketika

kita mengetik coding.

Gambar 2.1 Deklarasi Class1

Berikut source code Form1 :

Private Sub Command1_Click(Index As Integer)

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 5: API _ Class Module

If Not IsNumeric(Text1.Text) Then

MsgBox "Inputan harus angka!"

Else

If Index = 0 Then

Label4.Caption = hasil.lpersegi(Val(Text1.Text))

ElseIf Index = 1 Then

Label4.Caption = hasil.kpersegi(Val(Text1.Text))

End If

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Label4.Caption = ""

End Sub

Form2 :

Buat Form2 untuk bangun datar persegi panjang dan simpan dengan

nama bdPanjang.frm. Di dalam Form2, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = PERSEGI PANJANG

b. Label2, Name = Label2; Caption = PANJANG

c. Label3, Name = Label3; Caption = LEBAR

d. Label4, Name = Label4; Caption = HASIL:

e. Label5, Name = Label5; Caption = -

f. TextBox1, Name = Text1; Caption = -

g. TextBox2, Name = Text2; Caption = -

h. CommandButton1, Name = Command1; Caption = LUAS

i. CommandButton2, Name = Command1; Caption = KELILING

j. CommandButton3, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form2 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Then

MsgBox "Inputan harus angka!"

Else

If Index = 0 Then

Label5.Caption = hasil.lpanjang(Val(Text1.Text),

Val(Text2.Text))

Else

Label5.Caption = hasil.kpanjang(Val(Text1.Text),

Val(Text2.Text))

End If

End If

End Sub

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 6: API _ Class Module

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Label5.Caption = ""

End Sub

Form3 :

Buat Form3 untuk bangun datar segitiga dan simpan dengan nama

bdSegitiga.frm. Di dalam Form3, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = SEGITIGA

b. Label2, Name = Label2; Caption = ALAS

c. Label3, Name = Label3; Caption = TINGGI

d. Label4, Name = Label4; Caption = HASIL:

e. Label5, Name = Label5; Caption = -

f. TextBox1, Name = Text1; Caption = -

g. TextBox2, Name = Text2; Caption = -

h. CommandButton1, Name = Command1; Caption = LUAS

i. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form3 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Then

MsgBox "Inputan harus angka!"

Else

If Index = 0 Then

Label5.Caption = hasil.lsegitiga(Val(Text1.Text),

Val(Text2.Text))

End If

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Label5.Caption = ""

End Sub

Form4 :

Buat Form4 untuk bangun ruang Kubus dan simpan dengan nama

brKubus.frm. Di dalam Form4, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = -

b. Label2, Name = Label2; Caption = SISI

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = KUBUS

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 7: API _ Class Module

e. TextBox1, Name = Text1; Caption = -

f. CommandButton1, Name = Command1; Caption = VOLUME

g. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form4 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Then

MsgBox "Inputan harus angka!"

Else

Label1.Caption = hasil.vkubus(Val(Text1.Text))

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Label1.Caption = ""

End Sub

Form5 :

Buat Form5 untuk bangun ruang Balok dan simpan dengan nama

brBalok.frm. Di dalam Form5, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = -

b. Label2, Name = Label2; Caption = PANJANG

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = BALOK

e. Label5, Name = Label5; Caption = LEBAR

f. Label6, Name = Label6; Caption = TINGGI

g. TextBox1, Name = Text1; Caption = -

h. TextBox2, Name = Text2; Caption = -

i. TextBox3, Name = Text3; Caption = -

j. CommandButton1, Name = Command1; Caption = VOLUME

k. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form5 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Or Not

IsNumeric(Text3.Text) Then

MsgBox "Inputan harus angka!"

Else

Label1.Caption = hasil.vbalok(Val(Text1.Text), Val(Text2.Text),

Val(Text3.Text))

End If

End Sub

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 8: API _ Class Module

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Label1.Caption = ""

End Sub

Form6 :

Buat Form6 untuk bangun datar Lingkaran dan simpan dengan

nama bdLingkaran.frm. Di dalam Form6, buat object sebagai

berikut :

a. Label1, Name = Label1; Caption = LINGKARAN

b. Label2, Name = Label2; Caption = JARI-JARI

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = -

e. TextBox1, Name = Text1; Caption = -

f. CommandButton1, Name = Command1; Caption = LUAS

g. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form6 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Then

MsgBox "Inputan harus angka!"

Else

Label4.Caption = hasil.llingkaran(Val(Text1.Text))

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Label4.Caption = ""

End Sub

Form7 :

Buat Form7 untuk bangun datar Jajar Genjang dan simpan dengan

nama bdJajarGenjang.frm. Di dalam Form7, buat object sebagai

berikut :

a. Label1, Name = Label1; Caption = JAJAR GENJANG

b. Label2, Name = Label2; Caption = ALAS

c. Label3, Name = Label3; Caption = TINGGI

d. Label4, Name = Label4; Caption = HASIL:

e. Label5, Name = Label5; Caption = -

f. TextBox1, Name = Text1; Caption = -

g. TextBox2, Name = Text2; Caption = -

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 9: API _ Class Module

h. CommandButton1, Name = Command1; Caption = LUAS

i. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form7 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Then

MsgBox "Inputan harus angka!"

Else

Label5.Caption = hasil.ljg(Val(Text1.Text), Val(Text2.Text))

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Label5.Caption = ""

End Sub

Form8 :

Buat Form 8 untuk bangun datar Belah Ketupat dan simpan dengan

nama bdBelahKetupat.frm. Di dalam Form8, buat object sebagai

berikut :

a. Label1, Name = Label1; Caption = BELAH KETUPAT

b. Label2, Name = Label2; Caption = DIAGONAL 1

c. Label3, Name = Label3; Caption = DIAGONAL 2

d. Label4, Name = Label4; Caption = HASIL:

e. Label5, Name = Label5; Caption = -

f. TextBox1, Name = Text1; Caption = -

g. TextBox2, Name = Text2; Caption = -

h. CommandButton1, Name = Command1; Caption = LUAS

i. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form8 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Then

MsgBox "Inputan harus angka!"

Else

Label5.Caption = hasil.lbkll(Val(Text1.Text), Val(Text2.Text))

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 10: API _ Class Module

Label5.Caption = ""

End Sub

Form9 :

Buat Form9 untuk bangun datar layang-layang dan simpan dengan

nama bdLayang2.frm. Di dalam Form9, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = LAYANG-LAYANG

b. Label2, Name = Label2; Caption = DIAGONAL 1

c. Label3, Name = Label3; Caption = DIAGONAL 2

d. Label4, Name = Label4; Caption = HASIL:

e. Label5, Name = Label5; Caption = -

f. TextBox1, Name = Text1; Caption = -

g. TextBox2, Name = Text2; Caption = -

h. CommandButton1, Name = Command1; Caption = LUAS

i. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form9 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Then

MsgBox "Inputan harus angka!"

Else

Label5.Caption = hasil.lbkll(Val(Text1.Text), Val(Text2.Text))

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Label5.Caption = ""

End Sub

Form10 :

Buat Form10 untuk bangun ruang Kerucut dan simpan dengan nama

brKerucut.frm. Di dalam Form10, buat object sebagai berikut:

a. Label1, Name = Label1; Caption = -

b. Label2, Name = Label2; Caption = JARI-JARI

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = KERUCUT

e. Label5, Name = Label5; Caption = TINGGI

f. Label6, Name = Label6; Caption = SISI MIRING

g. TextBox1, Name = Text1; Caption = -

h. TextBox2, Name = Text2; Caption = -

i. TextBox3, Name = Text3; Caption = -

j. CommandButton1, Name = Command1; Caption = VOLUME

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 11: API _ Class Module

k. CommandButton1, Name = Command1; Caption = LUAS

l. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form10 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Or Not

IsNumeric(Text3.Text) Then

MsgBox "Inputan harus angka!"

Else

If Index = 0 Then

Label1.Caption = hasil.vkerucut(Val(Text1.Text),

Val(Text2.Text))

Else

Label1.Caption = hasil.lkerucut(Val(Text1.Text),

Val(Text3.Text))

End If

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Label1.Caption = ""

End Sub

Form11 :

Buat Form11 untuk bangun ruang Limas dan simpan dengan nama

brLimas.frm. Di dalam Form11, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = -

b. Label2, Name = Label2; Caption = PANJANG

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = LIMAS SEGI EMPAT

e. Label5, Name = Label5; Caption = LEBAR

f. Label6, Name = Label6; Caption = TINGGI

g. TextBox1, Name = Text1; Caption = -

h. TextBox2, Name = Text2; Caption = -

i. TextBox3, Name = Text3; Caption = -

j. CommandButton1, Name = Command1; Caption = VOLUME

k. CommandButton1, Name = Command1; Caption = LUAS

l. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form11 :

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 12: API _ Class Module

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Or Not

IsNumeric(Text3.Text) Then

MsgBox "Inputan harus angka!"

Else

If Index = 0 Then

Label1.Caption = hasil.vlimas(Val(Text1.Text),

Val(Text2.Text), Val(Text3.Text))

Else

Label1.Caption = hasil.llimas(Val(Text1.Text),

Val(Text2.Text), Val(Text3.Text))

End If

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Label1.Caption = ""

End Sub

Form12 :

Buat Form12 untuk bangun ruang Tabung dan simpan dengan nama

brTabung.frm. Di dalam Form12, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = -

b. Label2, Name = Label2; Caption = JARI-JARI

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = TABUNG

e. Label5, Name = Label5; Caption = TINGGI

f. TextBox1, Name = Text1; Caption = -

g. TextBox2, Name = Text2; Caption = -

h. CommandButton1, Name = Command1; Caption = VOLUME

i. CommandButton1, Name = Command1; Caption = LUAS

j. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form12 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Then

MsgBox "Inputan harus angka!"

Else

If Index = 0 Then

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 13: API _ Class Module

Label1.Caption = hasil.vtabung(Val(Text1.Text),

Val(Text2.Text))

Else

Label1.Caption = hasil.ltabung(Val(Text1.Text),

Val(Text2.Text))

End If

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Text1.Text = ""

Text2.Text = ""

Label1.Caption = ""

End Sub

Form13 :

Buat Form13 untuk bangun ruang Bola dan simpan dengan nama

brBola.frm. Di dalam Form13, buat object sebagai berikut :

a. Label1, Name = Label1; Caption = -

b. Label2, Name = Label2; Caption = JARI-JARI

c. Label3, Name = Label3; Caption = HASIL:

d. Label4, Name = Label4; Caption = BOLA

e. Label5, Name = Label5; Caption = TINGGI

f. TextBox1, Name = Text1; Caption = -

g. TextBox2, Name = Text2; Caption = -

h. CommandButton1, Name = Command1; Caption = VOLUME

i. CommandButton1, Name = Command1; Caption = LUAS

j. CommandButton2, Name = Command2; Caption = HAPUS

Deklarasi class module menjadi variabel bertipe object :

Dim hasil As New Class1

Berikut source code Form13 :

Private Sub Command1_Click(Index As Integer)

If Not IsNumeric(Text1.Text) Or Not IsNumeric(Text2.Text) Then

MsgBox "Inputan harus angka!"

Else

If Index = 0 Then

Label1.Caption = hasil.vbola(Val(Text1.Text),

Val(Text2.Text))

Else

Label1.Caption = hasil.lbola(Val(Text1.Text),

Val(Text2.Text))

End If

End If

End Sub

Private Sub Command2_Click(Index As Integer)

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 14: API _ Class Module

Text1.Text = ""

Text2.Text = ""

Label1.Caption = ""

End Sub

MDIForm1 :

Buat suatu menu MDIForm1 dengan menggunakan menu editor dan

simpan dengan nama MDIForm.frm.

Gambar 2.2 Menu Editor

Berikut source code dari MDIForm1 :

Private Sub bdbk_Click()

Form8.Show

End Sub

Private Sub bdjg_Click()

Form7.Show

End Sub

Private Sub bdlingkaran_Click()

Form6.Show

End Sub

Private Sub bdll_Click()

Form9.Show

End Sub

Private Sub bdpanjang_Click()

Form2.Show

End Sub

Private Sub bdpersegi_Click()

Form1.Show

End Sub

Private Sub bdsegitiga_Click()

Form3.Show

End Sub

Private Sub brbalok_Click()

Form5.Show

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 15: API _ Class Module

End Sub

Private Sub brbola_Click()

Form13.Show

End Sub

Private Sub brkerucut_Click()

Form10.Show

End Sub

Private Sub brkubus_Click()

Form4.Show

End Sub

Private Sub brlimas_Click()

Form11.Show

End Sub

Private Sub brtabung_Click()

Form12.Show

End Sub

Saat kita menjalankan program akan muncul tampilan awal yang

memiliki dua menu, yaitu menu Bangun Datar dan Bangun Ruang.

Di dalam menu Bangun Datar terdapat sub menu Pesegi, Persegi

Panjang, Segitiga, Lingkaran, Jajar Genjang, Belah Ketupat, dan

Layang-Layang. Di dalam menu Bangun Ruang terdapat sub menu

Kubus, Balok, Kerucut, Limas Segiempat, Tabung, dan Bola.

Gambar 2.3 Tampilan awal program

Jika kita memilih menu Bangun Datar kemudian mengklik sub

menu Persegi, maka akan tampil window Persegi.

Gambar 2.4 Window Persegi

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 16: API _ Class Module

Jika kita menginputkan sisinya dengan angka 4 dan mengklik

tombol Luas, maka akan tampil hasilnya 16.

Gambar 2.5 Perhitungan Luas Persegi

Jika kita menginputkan sisinya dengan angka 4 dan mengklik

tombol Keliling, maka akan tampil hasilnya 8.

Gambar 2.6 Perhitungan Keliling Persegi

Jika kita mengklik tombol Hapus, maka TextBox sisi dan Label

hasil akan terhapus.

Gambar 2.7 Fungsi Tombol Hapus

Jika kita menginputkan huruf atau kita belum menginputkan angka,

maka akan muncul MessageBox “Inputan harus angka!”.

Gambar 2.8 MessageBox

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 17: API _ Class Module

Gambar 2.9 Perhitungan Luas Persegi Panjang

Gambar 2.10 Perhitungan Keliling Persegi Panjang

Gambar 2.11 Perhitungan Luas Segitiga

Gambar 2.12 Perhitungan Luas Lingkaran

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 18: API _ Class Module

Gambar 2.13 Perhitungan Luas Jajar Genjang

Gambar 2.14 Perhitungan Luas Belah Ketupat

Gambar 2.15 Perhitungan Luas Layang-Layang

Gambar 2.16 Perhitungan Volume Kubus

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 19: API _ Class Module

Gambar 2.17 Perhitungan Volume Balok

Gambar 2.18 Perhitungan Volume Kerucut

Gambar 2.19 Perhitungan Luas Kerucut

Gambar 2.20 Perhitungan Volume Limas Segi Empat

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 20: API _ Class Module

Gambar 2.21 Perhitungan Luas Limas Segi Empat

Gambar 2.22 Perhitungan Volume Tabung

Gambar 2.23 Perhitungan Luas Tabung

Gambar 2.24 Perhitungan Volume Bola

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27

Page 21: API _ Class Module

Gambar 2.25 Perhitungan Luas Bola

BUKU PEMROGRAMAN API _ BAB 2 CLASS MODULE Page 27