Sabtu

1. Memodifikasi Program If dan Case

Gambar Setelah di RUN



Gambar Setelah Di klik Isi Data


Gambar Setelah Di Klik Clear



Kode / listing Program 

Public Class Form1
    
    Private Sub Cmdkode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmdkode.SelectedIndexChanged
        Dim kdbarang, namabarang As String
        Dim harga As Single
        kdbarang = Cmdkode.Text

        Select Case kdbarang
            Case "SPT"
                namabarang = "Sepatu"
                harga = 200000
            Case "SND"
                namabarang = "Sandal"
                harga = 100000
            Case "TST"
                namabarang = "T-Shirt"
                harga = 1500000
            Case "TOP"
                namabarang = "Topi"
                harga = 500000
            Case "TAS"
                namabarang = "Tas"
                harga = 350000
            Case Else
                namabarang = "-"
                harga = 0

        End Select
        Txtnamabarang.Text = namabarang
        Txthargabarang.Text = harga
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Control As Windows.Forms.Control
        For Each Control In Me.Controls
            Control.Enabled = False
            BtIsi.Enabled = True
            Bttutup.Enabled = True

        Next
        Cmdkode.Items.Add("SPT")
        Cmdkode.Items.Add("SND")
        Cmdkode.Items.Add("TST")
        Cmdkode.Items.Add("TOP")
        Cmdkode.Items.Add("TAS")


    End Sub

    Private Sub Txtjmlbarang_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txtjmlbarang.TextChanged
        Txttohar.Text = Val(Txthargabarang.Text) * Val(Txtjmlbarang.Text)
        Txtotalbayar.Text = Val(Txttohar.Text) - Val(Txtdiskon.Text)
    End Sub

    Private Sub Radiotunai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Radiotunai.CheckedChanged
        Txtdiskon.Text = Val(Txttohar.Text) * 10 / 100
        Txtotalbayar.Text = Val(Txttohar.Text) - Val(Txtdiskon.Text)
    End Sub

    Private Sub Radiokredit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Radiokredit.CheckedChanged
        Txtdiskon.Text = 0
        Txtotalbayar.Text = Val(Txttohar.Text) - Val(Txtdiskon.Text)
    End Sub

    Private Sub Btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclear.Click
        Dim control As Windows.Forms.Control
        For Each control In Me.Controls
            control.Enabled = False
            BtIsi.Enabled = True
            Bttutup.Enabled = True
        Next
        Txtotalbayar.Clear()
        Txtdiskon.Clear()
        Txthargabarang.Clear()
        Txtjmlbarang.Clear()
        Txtnamabarang.Clear()
        Txtotalbayar.Clear()
        Me.Radiotunai.Checked = False
        Me.Radiokredit.Checked = False
        Cmdkode.Text = ""

    End Sub

    Private Sub Bttutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bttutup.Click
        Me.Close()

    End Sub

    Private Sub BtIsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtIsi.Click
        Dim control As Windows.Forms.Control
        For Each control In Me.Controls
            control.Enabled = True
            BtIsi.Enabled = False
        Next

    End Sub
End Class


2. Membuat Puzzel Sederhana


Gambar Setelah Di RUN



Gambar Setelah Berhasil Mengurutkan



Kode / listing Program

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim control As Windows.Forms.Control
        For Each control In Me.Controls
            If control.GetType.Name = "Button" Then
                Dim rndnumber As Random
                Dim number As Integer
                rndnumber = New Random
                number = rndnumber.Next(1, 9)
                control.Text = number

                If Button2.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button2.Text = number
                    Loop Until Button2.Text <> Button1.Text
                End If

                If Button3.Text = Button2.Text Or Button3.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button3.Text = number
                    Loop Until Button3.Text <> Button2.Text And Button3.Text <> Button1.Text
                End If

                If Button4.Text = Button3.Text Or Button4.Text = Button2.Text Or Button4.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button4.Text = number
                    Loop Until Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text
                End If

                If Button4.Text = Button3.Text Or Button4.Text = Button2.Text Or Button4.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button4.Text = number
                    Loop Until Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text
                End If

                If Button5.Text = Button4.Text Or Button5.Text = Button3.Text Or Button5.Text = Button2.Text Or Button5.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button5.Text = number
                    Loop Until Button5.Text <> Button4.Text And Button5.Text <> Button3.Text And Button5.Text <> Button2.Text And Button5.Text <> Button1.Text
                End If

                If Button6.Text = Button5.Text Or Button6.Text = Button4.Text Or Button6.Text = Button3.Text Or Button6.Text = Button2.Text Or Button6.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button6.Text = number
                    Loop Until Button6.Text <> Button5.Text And Button6.Text <> Button3.Text And Button6.Text <> Button2.Text And Button6.Text <> Button1.Text
                End If

                If Button7.Text = Button6.Text Or Button7.Text = Button5.Text Or Button7.Text = Button4.Text Or Button7.Text = Button3.Text Or Button7.Text = Button2.Text Or Button7.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button7.Text = number
                    Loop Until Button7.Text <> Button6.Text And Button7.Text <> Button5.Text And Button7.Text <> Button4.Text And Button7.Text <> Button3.Text And Button7.Text <> Button2.Text And Button7.Text <> Button1.Text
                End If

                If Button8.Text = Button7.Text Or Button8.Text = Button6.Text Or Button8.Text = Button5.Text Or Button8.Text = Button4.Text Or Button8.Text = Button3.Text Or Button8.Text = Button2.Text Or Button8.Text = Button1.Text Then
                    Do
                        number = rndnumber.Next(1, 9)
                        Button8.Text = number
                    Loop Until Button8.Text <> Button7.Text And Button8.Text <> Button6.Text And Button8.Text <> Button5.Text And Button8.Text <> Button4.Text And Button8.Text <> Button3.Text And Button8.Text <> Button2.Text And Button8.Text <> Button1.Text
                End If
            End If
            Button9.Text = ""
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button2.Text = "" Then
            Button2.Text = Button1.Text
            Button1.Text = ""
        ElseIf Button4.Text = "" Then
            Button4.Text = Button1.Text
            Button1.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Button9.Text = "" Then
            Button9.Text = Button6.Text
            Button6.Text = ""
        ElseIf Button3.Text = "" Then
            Button3.Text = Button6.Text
            Button6.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button6.Text
            Button6.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button1.Text = "" Then
            Button1.Text = Button4.Text
            Button4.Text = ""
        ElseIf Button7.Text = "" Then
            Button7.Text = Button4.Text
            Button4.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button4.Text
            Button4.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button1.Text = "" Then
            Button1.Text = Button2.Text
            Button2.Text = ""
        ElseIf Button3.Text = "" Then
            Button3.Text = Button2.Text
            Button2.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button2.Text
            Button2.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Button7.Text = "" Then
            Button7.Text = Button8.Text
            Button8.Text = ""
        ElseIf Button9.Text = "" Then
            Button9.Text = Button8.Text
            Button8.Text = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button8.Text
            Button8.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Button2.Text = "" Then
            Button2.Text = Button5.Text
            Button5.Text = ""
        ElseIf Button4.Text = "" Then
            Button4.Text = Button5.Text
            Button5.Text = ""
        ElseIf Button6.Text = "" Then
            Button6.Text = Button5.Text
            Button5.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.Text = Button5.Text
            Button5.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button2.Text = "" Then
            Button2.Text = Button3.Text
            Button3.Text = ""
        ElseIf Button6.Text = "" Then
            Button6.Text = Button3.Text
            Button3.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Button4.Text = "" Then
            Button4.Text = Button7.Text
            Button7.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.Text = Button7.Text
            Button7.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Button6.Text = "" Then
            Button6.Text = Button9.Text
            Button9.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.Text = Button9.Text
            Button9.Text = ""
        End If
        If Button1.Text = "1" And Button2.Text = "2" And Button3.Text = "3" And Button4.Text = "4" And Button5.Text = "5" And Button6.Text = "6" And Button7.Text = "7" And Button8.Text = "8" And Button9.Text = "" Then
            MsgBox("Selamat Anda Menang")
        End If
    End Sub
End Class


Aplikasi Download Disini


Jawaban Latihan 1

1. Yang menyebabkan program eror pada batalamat1_click baris program alamat = “Kuningan” adalah inisiali yang tidak jelas seharusnya jika ingin menggunakan inisialisasi pada Private sub maka inisialisasinya ditambah Dim alamat As String namun bila ingin menggunakan inisialisasi pada Public Class maka inisialisasi pada Private sub di hapus atau dinonaktifkan menggunakan tanda(‘) begitu juga jika ingin menggunakan inisialisasi pada modul maka inisiali sasi pada Private sub dan Public Class dinonaktifkan atau dihapus.
2. Karena pada nama1 target sudah di inisialisasikan yaitu Dim nama As String nama = "Nandang" Txtnama.Text = nama Sedangkan pada nama2 target belum diinisialisasikan sehingga jika di klik akan kosong sehingga berbeda. Pada alamat1 sudah diinisialisasikan baik pada Private sub maupun pada Public Class walaupun itu menyebabkan eror. sedangkan pada alamat2 walaupun belum diinisialisasikan pada Private Sub tetapi sudah di inisialisasikan pada Public Class sehingga jika diklik tetap sama.
 3. Karena Pada tombol tambah umur 1 menggunakan Dim umur As Integer, seharusnya Dim diganti dengan Static menjadi Static As Integer sehingga saat ditekan tombol tambah umur 1, umur bertambah 1 dari sebelumnya.
4. Menurut saya tidak ada masalah pada form dua karena semua sudah di deklarasikan pada Modul sehingga walaupun tidak dideklarasikan pada Private Sub dan Public Class masih bisa Dieksekusi karena Program mengambil apa yang telah dideklarasikan dimodul.

Jawaban Latihan 2

Kelemahan pada program If dan Case adalah pada Kode TAS karena belum Di beri nama barang dan harga. Sehingga jika program dieksekusi dan kode barang di pilih TAS maka Hasilnya akan kosong, tidak seperti kode barang lainya yang telah diinisialisasikan nama dan harganya.

 Sebelum di perbaiki




Sesudah di perbaiki






Aplikasi Download Disini

Jumat

Aplikisi dibuat untuk mempermudahkan kita dalam mencari luas dan keliling persegipanjang.


Hasil :




download disini


Subscribe to RSS Feed Follow me on Twitter!