Posted by : Unknown Selasa, 11 Juni 2013


MEMBUAT BASE CLASS DAN SUB CLASS UNTUK PROGRAM TELP SELULER.EXE

1.       Buka Visual Studio 2012, New project dan pilih Form, dan masukaan kode berikut.
Public Class Form1

    Private Sub button1_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'hp jadul
        Dim hpjadul As New classHP

        With hpjadul
            .nama = "3310"
            .pabrikan = "Nok Yaya"
            .kirimSMS("mama minta pulsa")
        End With

        MessageBox.Show("status terahir hp" & hpjadul.nama & ":" & hpjadul.status)

        'dim hp baru
        Dim hpbaru As New ClassSmartphone

        With hpbaru
            .nama = "lumpia"
            .pabrikan = "nok yaya"
            .KirimSMS("mama minta pulsa")
            .internetan()
        End With

        MessageBox.Show("status terahir hp" & hpbaru.nama & ":" & hpbaru.status)
    End Sub
End Class


2.       Buat class baru dengan klik kanan pada PR BUAT TELEPON SELULER (nama file vb) à aad àclass, lalu beri nama class tersebut dengan nama ClassSmartPhone.vb àkemudian masukan kode dibawah ini kedalam kelas tersebut.
Public Class ClassSmartPhone
    Inherits classHP

    Public Sub internetan()
        status = "sedang internetan"
    End Sub

    Public Sub New()
        MessageBox.Show(jenis)
    End Sub
End Class




3.       Buat kelas baru lage dan beri nama classHP.vb, dan masukan kode berikut.
Public Class classHP

    Private isipesan As String
    Private m_nama As String
    Private m_pabrikan As String
    Private m_status As String

    Public ReadOnly Property jenis() As String
        Get
            Return "telepon seluler"
        End Get
    End Property

    Public Property nama() As String
        Get
            Return m_nama
        End Get
        Set(ByVal nilai As String)
            m_nama = nilai
        End Set
    End Property

    Public Property pabrikan() As String
        Get
            Return m_pabrikan
        End Get
        Set(ByVal nilai As String)
            m_pabrikan = nilai
        End Set
    End Property

    Public Property status() As String
        Get
            Return m_status
        End Get
        Set(ByVal nilai As String)
            m_status = nilai
        End Set
    End Property

    Public Sub kirimSMS(ByVal nilai As String)
        isipesan = nilai
        status = "sedang kirim sms"
    End Sub

    Public Sub talk(ByVal nilai As String)
        isipesan = nilai
        status = "sedang telponan"
    End Sub

End Class


4.       Setelah selesai  tekan start program atau tekan F5.





{ 1 komentar ... read them below or add one }

Random Post

Copyright © 2015 Mbah Second - Edited by Mbah Second - Powered by Blogger - Designed by Johanes Djogan Metrominimalist