Visual Basic Lanjutan Praktikum 6 - Object Oriented Programming (OOP)
Wednesday, April 15, 2020
1 Comment
Laptopinformatika.com - Kemarin kita sudah bahas VB yang teori 6 dan sekarang kita lanjutkan dengan praktikum 6. Hari ini saya akan memberikan konten yang berisi tentang "Membuat Class dan diakses dari Form GUI" Oke langsung saja kita bahas yah tanpa banyak basa-basi hehehe, check it out...
Untuk Latihan-latihan sebelumnya ada di link bawah ini, jika kalian ingin mempelajari semuanya silahkan klik link di bawah ini :
- Visual Basic Lanjutan Teori 1 Variabel dan Type Data
- Visual Basic Lanjutan Praktikum 1 Operator
- Visual Basic Lanjutan Teori 2 Percabangan (Struktur If-Then, If-Then-Else, Nested IF)
- Visual Basic Lanjutan Praktikum 2 Percabangan (IIF dan Select Case)
- Visual Basic Lanjutan Teori 3 - Perulangan
- Visual Basic Lanjutan Praktikum 3 - Perulangan (Do While - Loop)
- Visual Basic Lanjutan Teori 4 - Array Dimensi Satu
- Visual Basic Lanjutan Praktikum 4 - Array Dimensi Dua
- Visual Basic Lanjutan Teori 5 - Procedure dan Function
- Visual Basic Lanjutan Praktikum 5 - Procedure dan Function
- Visual Basic Lanjutan Teori 6 - Object Oriented Programming (OOP)
Read More : Cara Mengetahui Password WiFi dengan CMD 100% Berhasil Terbaru
OOP GUI
1. Buatlah Class di Project_OOP / WindowsApplication1 dengan nama ClassDay.
2. Buatlah Class di Project_OOP / WindowsApplication1 dengan nama ClassDay.
3. Buatlah Form di Project_OOP / WindowsApplication1 dengan nama FormHari.
Read More : 5 Kesalahan Umum Prototipe Cepat Yang Perlu Anda Ketahui
Latihan 1
- Source Code
Form Class
Public Class ClassDay
Dim hari As String
Public Sub GetDay() 'laptopinformatika.com
hari = "Senin"
MessageBox.Show("Hari ini adalah : " & hari)
End Sub
End Class
Form1
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "LaptopInformatika.com"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Mendeklarasikan variable dan mereferensikan ke ClassDay
Dim hari As New ClassDay 'laptopinformatika.com
hari.GetDay()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim message As String
message = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.com")
If message = vbYes Then 'laptopinformatika.com
End
End If
End Sub
End Class
Latihan 2
- Source Code
Form Class
Public Class ClassCircle
Dim phi As Decimal = CDec(3.14) 'laptopinformatika.com
Dim r As Decimal
Public Sub GetArea()
phi = CDec(3.14) 'laptopinformatika.com
r = 10
MessageBox.Show("Luas Lingkaran = " & phi * r ^ 2)
End Sub
End Class
Form2
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "LaptopInformatika.com"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lingkaran As New ClassCircle 'laptopinformatika.com
lingkaran.GetArea()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim message As String
message = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.com")
If message = vbYes Then 'laptopinformatika.com
End
End If
End Sub
End Class
Read More : Cara Mengaktifkan Wifi yang ter-Disable di Windows 10 Terbaru 2020
Latihan 3
- Source Code
Form Class
Public Class ClassMahasiswa
'Deklarasi Variable
Private nama As String 'laptopinformatika.com
'Membuat Method
Public Function getNama()
Return nama
End Function
Public Sub setNama(ByRef nm As String)
nama = nm 'laptopinformatika.com
End Sub
End Class
Form3
Public Class Form3
Public mahasiswa As New ClassMahasiswa
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "LaptopInformatika.com"
mahasiswa = New ClassMahasiswa
mahasiswa.setNama("Ilham Ramadhan")
MsgBox("Nama Anda : " + mahasiswa.getNama())
End Sub
End Class
Kasus 1
- Source Code
Form Class
Public Class ClassLuasSegitiga
Dim alas As Decimal
Dim tinggi As Decimal
Public Sub GetLuas() 'laptopinformatika.com
alas = 13
tinggi = 14
MessageBox.Show("Luas Segitiga = " & 0.5 * alas * tinggi)
End Sub
End Class
Form4
Public Class Form4
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "LaptopInformatika.com"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim segitiga As New ClassLuasSegitiga
segitiga.GetLuas()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim message As String
message = MsgBox("Are you sure want to exit ?", vbYesNo, "laptopinformatika.com")
If message = vbYes Then
End
End If
End Sub
End Class
Oke mungkin segitu dulu ya untuk pelajarannya hari ini, semoga bermanfaat, thank you see you next again :D
This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! real genuine leather messenger bags
ReplyDelete