Sabtu, 28 April 2012

Membuat Program Konsep Pemrograman Object Oriented Programming (OOP) ke Dalaam Visual Basic 2008

Assalamualaikum Wr. Wb.
Pada kesempatan kali ini saya akan menjelaskan program sederhana yang telah saya buat yaitu program aplikasi tulisan font berwarna dan selanjutnya mengambil kata dari tulisan yang dibuat sebelumnya. Program tersebut saya buat degan menggunakan Microsoft Visual Studio 2008 dan memakai fungsi Left, Mid, Right dan Class. 



1. Pertama-tama kita membuka Microsoft Visual Studio 2008 lalu membuat project dengan:
klik Create Project > Windows Form Application > Ok kemudian membuat Project Class  klik Project>Add Class seperti dibawah ini


2. Setelah mengklik Add Class, kita ubah nama Class tersebut menjadi Font Property lalu klik Add seperti gambar dibawah ini berikut codingannya :




Public Class FontProperty
    Public Function kiri(ByVal karakter, ByVal jumlah)
        kiri = Left(karakter, jumlah)
    End Function

    Public Function kanan(ByVal karakter, ByVal jumlah)
        kanan = Right(karakter, jumlah)
    End Function

    Public Function tengah(ByVal karakter, ByVal jumlahmulai, ByVal jumlahambil)
        tengah = Mid(karakter, jumlahmulai, jumlahambil)
    End Function
End Class



3. Kemudian Buat Formnya 1 Label, 9 TextBox, 2 Button, 1 GroupBox, 4 RadioButton, 3 CheckBox


4. Jangan lupa mengubah Name dan Text di Properties


5.  Double klik Button OK , Button Get Word, RadioButton merah, hijau, biru, kuning serta CheckBox Bold, Italic dan Underline ddengan codingan sebagai berikut :



Public Class Form1

    Dim classfont As New FontProperty

    Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
        Thasil.Text = Tnama.Text
    End Sub

    Private Sub Tmerah_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tmerah.CheckedChanged
        Thasil.ForeColor = Color.Red
    End Sub

    Private Sub Thijau_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Thijau.CheckedChanged
        Thasil.ForeColor = Color.Green
    End Sub

    Private Sub Tbiru_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbiru.CheckedChanged
        Thasil.ForeColor = Color.Blue
    End Sub

    Private Sub Tkuning_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tkuning.CheckedChanged
        Thasil.ForeColor = Color.Yellow
    End Sub

    Private Sub Titalic_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Titalic.CheckedChanged
        If Titalic.Checked Then
            Thasil.Font = New Font(Thasil.Font, Thasil.Font.Style Or FontStyle.Italic)
        Else
            Thasil.Font = New Font(Thasil.Font, Thasil.Font.Style And Not FontStyle.Italic)
        End If
    End Sub

    Private Sub Tbold_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbold.CheckedChanged
        If Tbold.Checked Then
            Thasil.Font = New Font(Thasil.Font, Thasil.Font.Style Or FontStyle.Bold)
        Else
            Thasil.Font = New Font(Thasil.Font, Thasil.Font.Style And Not FontStyle.Bold)
        End If
    End Sub

    Private Sub Tunderline_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tunderline.CheckedChanged
        If Tunderline.Checked Then
            Thasil.Font = New Font(Thasil.Font, Thasil.Font.Style Or FontStyle.Underline)
        Else
            Thasil.Font = New Font(Thasil.Font, Thasil.Font.Style And Not FontStyle.Underline)
        End If
    End Sub

Private Sub BtnGetWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetWord.Click
        Dim f As Integer
        f = Left.Text
        TGetW.Text = classfont.kiri(Thasil.Text, f)
        Dim r As Integer
        Dim s As Integer
        r = MID1.Text
        s = MID2.Text
        TGetW2.Text = classfont.tengah(Thasil.Text, r, s)
        Dim y As Integer
        y = Right.Text
        TGetW3.Text = classfont.kanan(Thasil.Text, y)
    End Sub

6. Kemudian klik Start atau Debug lalu isi di TextBox Masukan Nama klik OK dan pilih warna dan bentuk yang anda sukai isi kolom kecil dengan angka disana akan menampilkan kata-kata yang anda tulis tadi dengan mengambil huruf dari kiri, tengah, dan kiri kemudian klik Get Word dan hasilnya seperti ini :


Sekian program class sederhana dari saya semoga bermanfaat jika ada program yang salah atau kurang silahkan isi comment dibawah ini.
Wassalamualaikum Wr. Wb




TERIMA KASIH :)



Tidak ada komentar:

Posting Komentar