look at me

SELAMAT DATANG MAS, MBAK, OM, TANTE, PAKDHE,BUDHE DAN SEMUANYA

Senin, 29 Oktober 2012

GAME PUZLE “TEKA-TEKI BINGUNG”

       Seperti yang saya janjikan di postingan sebelumnya, postingan kali ini saya akan membahas sebuah game puzle buatanku sendiri. Game ini saya beri nama “Teka-Teki Bingung”. Namanya saja “Teka-Teki Bingung”, ya game ini bukan game yang bisa dimainkan dengan mudah. Nah ini lah tampilan utama dari game ini
Mungkin bagi sebagian orang game di atas sudah sangat familiar dan dengan mudahnya dimainkan. Nah bagi yang belum pernah memainkannya, nih cara memainkannya cukup menyusun angka-angka yang sudah di acak-acak menjadi sebuah urutan angka 1 sampai delapan.

Dan jika pemain bisa memcahkan misteri “Teka-Teki Bingung” ini maka akan tampil dialog box seperti ini
 Game ini dilengkapi fitur timer untuk mengukur kecepatan pemain dalam menyusun angka-angka tersebut. Selain fungsi timer ada fitur langkah untuk menghitung langkah yang dilakukan oleh pemain untuk menyusun angka-angka tersebut, semakin sedikit langkah maka pemain semakin efisien dalam menyusun angka-angka tersebut.
Tombol reset digunakan untuk kembali mengacak angka dan mereset waktu serta dan jumlah langkah yang dilakukan jadi semuanya kembali ke awal, dan tombol “Keluar” tentu saja digunakan untuk keluar/ menutup game tersebut
Sebenarnya dalam pembuatan game ini cukup simple kalau kita mengetahui beberapa trik yang bisa digunakan. Trik-trik yang digunakan adalah sebagai berikut:

Penggunaan Rnd() untuk menghasilkan angka acak
Conntohnya :
Bt1.Text = Convert.ToInt32(Rnd() * 8)

Penggunaan If...ElseIf  serta pertukaran nilai untuk melakukan pengecekan serta melakukan pergeseran angka
Contohnya:
If (Bt2.Text = "") Then
            tampung = Bt1.Text
            Bt1.Text = Bt2.Text
            Bt2.Text = tampung
            move += 1
            Txtmove.Text = move

Nah itu tadi beberapa trik inti yang saya gunakan untuk membangun game “Teka-Teki Bingung” tersebut. Tetapi untuk lebih lengkapnya, berikut kode sumber yang saya gunakan untuk membangunnya
Public Class Form1
    Dim detik, menit, move As Integer
    Private Sub Bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt1.Click
        Dim tampung As String = ""

        If (Bt2.Text = "") Then
            tampung = Bt1.Text
            Bt1.Text = Bt2.Text
            Bt2.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt4.Text = "") Then
            tampung = Bt1.Text
            Bt1.Text = Bt4.Text
            Bt4.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt2.Click
        Dim tampung As String = ""

        If (Bt1.Text = "") Then
            tampung = Bt2.Text
            Bt2.Text = Bt1.Text
            Bt1.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt5.Text = "") Then
            tampung = Bt2.Text
            Bt2.Text = Bt5.Text
            Bt5.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt3.Text = "") Then
            tampung = Bt2.Text
            Bt2.Text = Bt3.Text
            Bt3.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt3.Click
        Dim tampung As String = ""

        If (Bt2.Text = "") Then
            tampung = Bt3.Text
            Bt3.Text = Bt2.Text
            Bt2.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt6.Text = "") Then
            tampung = Bt3.Text
            Bt3.Text = Bt6.Text
            Bt6.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
        End If
    End Sub

    Private Sub Bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt4.Click
        Dim tampung As String = ""

        If (Bt1.Text = "") Then
            tampung = Bt4.Text
            Bt4.Text = Bt1.Text
            Bt1.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt5.Text = "") Then
            tampung = Bt4.Text
            Bt4.Text = Bt5.Text
            Bt5.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt7.Text = "") Then
            tampung = Bt4.Text
            Bt4.Text = Bt7.Text
            Bt7.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt5.Click
        Dim tampung As String = ""

        If (Bt2.Text = "") Then
            tampung = Bt5.Text
            Bt5.Text = Bt2.Text
            Bt2.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt4.Text = "") Then
            tampung = Bt5.Text
            Bt5.Text = Bt4.Text
            Bt4.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt8.Text = "") Then
            tampung = Bt5.Text
            Bt5.Text = Bt8.Text
            Bt8.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt6.Text = "") Then
            tampung = Bt5.Text
            Bt5.Text = Bt6.Text
            Bt6.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt6.Click
        Dim tampung As String = ""

        If (Bt3.Text = "") Then
            tampung = Bt6.Text
            Bt6.Text = Bt3.Text
            Bt3.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt5.Text = "") Then
            tampung = Bt6.Text
            Bt6.Text = Bt5.Text
            Bt5.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt9.Text = "") Then
            tampung = Bt6.Text
            Bt6.Text = Bt9.Text
            Bt9.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt7.Click
        Dim tampung As String = ""

        If (Bt4.Text = "") Then
            tampung = Bt7.Text
            Bt7.Text = Bt4.Text
            Bt4.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt8.Text = "") Then
            tampung = Bt7.Text
            Bt7.Text = Bt8.Text
            Bt8.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt8.Click
        Dim tampung As String = ""

        If (Bt7.Text = "") Then
            tampung = Bt8.Text
            Bt8.Text = Bt7.Text
            Bt7.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt5.Text = "") Then
            tampung = Bt8.Text
            Bt8.Text = Bt5.Text
            Bt5.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt9.Text = "") Then
            tampung = Bt8.Text
            Bt8.Text = Bt9.Text
            Bt9.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt9.Click
        Dim tampung As String = ""

        If (Bt8.Text = "") Then
            tampung = Bt9.Text
            Bt9.Text = Bt8.Text
            Bt8.Text = tampung
            move += 1
            Txtmove.Text = move
        ElseIf (Bt6.Text = "") Then
            tampung = Bt9.Text
            Bt9.Text = Bt6.Text
            Bt6.Text = tampung
            move += 1
            Txtmove.Text = move
        End If
        If (Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt9.Text = "") Then
            Timer1.Enabled = False
            Dim Control As Windows.Forms.Control
            For Each Control In Me.GroupBox1.Controls
                Control.Enabled = False
            Next
            MsgBox("Selamat Anda berhasil", vbInformation + vbOKOnly, "Selamat !!!!")
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Do
            Bt1.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt1.Text <> "0"
        Do
            Bt2.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt2.Text <> "0" And Bt2.Text <> Bt1.Text
        Do
            Bt3.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt3.Text <> "0" And Bt3.Text <> Bt1.Text And Bt3.Text <> Bt2.Text
        Do
            Bt4.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt4.Text <> "0" And Bt4.Text <> Bt1.Text And Bt4.Text <> Bt2.Text And Bt4.Text <> Bt3.Text
        Do
            Bt5.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt5.Text <> "0" And Bt5.Text <> Bt1.Text And Bt5.Text <> Bt2.Text And Bt5.Text <> Bt3.Text And Bt5.Text <> Bt4.Text
        Do
            Bt6.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt6.Text <> "0" And Bt6.Text <> Bt1.Text And Bt6.Text <> Bt2.Text And Bt6.Text <> Bt3.Text And Bt6.Text <> Bt4.Text And Bt6.Text <> Bt5.Text
        Do
            Bt7.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt7.Text <> "0" And Bt7.Text <> Bt1.Text And Bt7.Text <> Bt2.Text And Bt7.Text <> Bt3.Text And Bt7.Text <> Bt4.Text And Bt7.Text <> Bt5.Text And Bt7.Text <> Bt6.Text
        Do
            Bt8.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt8.Text <> "0" And Bt8.Text <> Bt1.Text And Bt8.Text <> Bt2.Text And Bt8.Text <> Bt3.Text And Bt8.Text <> Bt4.Text And Bt8.Text <> Bt5.Text And Bt8.Text <> Bt6.Text And Bt8.Text <> Bt7.Text
        Timer1.Enabled = True
    End Sub

    Private Sub Btreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btreset.Click
        detik = 0
        menit = 0
        txtmenit.Text = ""
        txtmenit.Text = ""
        Bt9.Text = ""
        move = 0
        Txtmove.Text = ""
        Timer1.Enabled = True
        Dim Control As Windows.Forms.Control
        For Each Control In Me.GroupBox1.Controls
            Control.Enabled = True
        Next
        Do
            Bt1.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt1.Text <> "0"
        Do
            Bt2.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt2.Text <> "0" And Bt2.Text <> Bt1.Text
        Do
            Bt3.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt3.Text <> "0" And Bt3.Text <> Bt1.Text And Bt3.Text <> Bt2.Text
        Do
            Bt4.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt4.Text <> "0" And Bt4.Text <> Bt1.Text And Bt4.Text <> Bt2.Text And Bt4.Text <> Bt3.Text
        Do
            Bt5.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt5.Text <> "0" And Bt5.Text <> Bt1.Text And Bt5.Text <> Bt2.Text And Bt5.Text <> Bt3.Text And Bt5.Text <> Bt4.Text
        Do
            Bt6.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt6.Text <> "0" And Bt6.Text <> Bt1.Text And Bt6.Text <> Bt2.Text And Bt6.Text <> Bt3.Text And Bt6.Text <> Bt4.Text And Bt6.Text <> Bt5.Text
        Do
            Bt7.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt7.Text <> "0" And Bt7.Text <> Bt1.Text And Bt7.Text <> Bt2.Text And Bt7.Text <> Bt3.Text And Bt7.Text <> Bt4.Text And Bt7.Text <> Bt5.Text And Bt7.Text <> Bt6.Text
        Do
            Bt8.Text = Convert.ToInt32(Rnd() * 8)
        Loop Until Bt8.Text <> "0" And Bt8.Text <> Bt1.Text And Bt8.Text <> Bt2.Text And Bt8.Text <> Bt3.Text And Bt8.Text <> Bt4.Text And Bt8.Text <> Bt5.Text And Bt8.Text <> Bt6.Text And Bt8.Text <> Bt7.Text
      
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        detik += 1
        Txtdetik.Text = detik

        If (detik = 60) Then
            menit += 1
            txtmenit.Text = menit
            Txtdetik.Text = "0"
            detik = 0
        End If
    End Sub

    Private Sub Btkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btkeluar.Click
        My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
        If (MsgBox("Yakin untuk keluar ?" + vbNewLine + "Semua kemajuan permainan akan hilang", vbYesNo + vbQuestion + vbDefaultButton2, "Konfirmasi")) = vbYes Then
            End
        End If
    End Sub
End Class

Minggu, 28 Oktober 2012

Modifikasi Latihan If dan Case

Pada postingan sebelumnya saya dudah sempat membahas tugas membuat aplikasi kasir yang saya beri nama “Latihan If dan Case”. Nah untuk tugas kali ini saya dituntut untuk dapat memodifikasi aplikasi tersebut sesuai arahan dari Pak Nandang. Berikut aturan dalam memodifikasinya :
  1. Tambahkan tombol “Isi Data”
  2. Saat form dijalankan semua isian tidak aktif, tombol “Isi Data” dan tombol “Tutup” aktif tetapi tombol “Clear” tidak aktif.
  3. Saat ditekan tombol “Isi Data”,maka combo box “kode barang”, text box “jumlah barang”, radio button “cara beli” dan tombol “Clear” aktif tetapi tombol “Isi Data” tidak aktif.
  4. Saat tombol “Clear” ditekan maka yang dilakukan hampir sama dengan yang dilakukan ketika form dijalankan.
  5. Ketika memodifikasi kode sumber aplikasi tersebut harus mengandung statemen perulangan.

Sebenarnya jika kita telaah permasalahan-permasalahan tersebut ada beberapa trik yang bisa dilakukan. Berikut sekilas trik yang saya gunakan untuk menyelesaikan tantangan dari pak Nandang tersebut:

  • Untuk mengatasi permasalahan nomor dua tersebut saya cukup menggunakan perulangan For Each dan bermain-main dengan perintah Enabled. Perintah Enabled ini digunakan untuk menghidupkan/mematikan fungsi suatu objek yang ada dalam form. Untuk Lebih jelasnya berikut koding yang saya gunkan
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    cmbkode.Items.Add("SPT")
            cmbkode.Items.Add("SND")
            cmbkode.Items.Add("TST")
            cmbkode.Items.Add("TOP")
            cmbkode.Items.Add("TAS")

            Dim Control As Windows.Forms.Control
            For Each Control In Me.Controls
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "TextBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "RadioButton" Then
                    Control.Enabled = False
                End If
            Next
            Btclear.Enabled = False

    Koding tersebut akan dijalankan ketika form dimuat.
     
  •  Untuk mengatasi permasalahan nomer 3, hampir sama seperti langkah untuk memecahkan permasalahan nomer 2, perbedaanya hanya terdapat pada control yang diaktifkan atau dimatikan, dan berikut koding untuk melakukan hal tersebut
    Private Sub Btisidata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btisidata.Click
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
            Dim Control As Windows.Forms.Control

            For Each Control In Me.Controls
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = True
                End If
                If Control.GetType.Name = "RadioButton" Then
                    Control.Enabled = True
                End If
            Next
            txtjumlah.Enabled = True
            Btclear.Enabled = True
            Btisidata.Enabled = False


        End Sub
  • Sementara untuk permasalahan nomer 4 sebagian perintah yang digunakan sama seperti ketika form dimuat, lebih tepatnya adalah sebagai berikut
    My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
            Me.radiotunai.Checked = False
            Me.radiokredit.Checked = False
            txtbayar.Clear()
            txtdiskon.Clear()
            txtharga.Clear()
            txtjumlah.Clear()
            txtnama.Clear()
            txttotal.Clear()
            cmbkode.Text = ""


            Dim Control As Windows.Forms.Control
            For Each Control In Me.Controls
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "TextBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "RadioButton" Then
                    Control.Enabled = False
                End If
            Next
            Btclear.Enabled = False
            Btisidata.Enabled = True

        End Sub

    Nah uraian di atas merupakan beberapa trik yang saya gunakan dalam menyelesaikan tantangan-tantangan yang telah saya sebutkan sebelumnya, tetapi untuk lebih lengkapnya monggo disimak kode sumber yang saya gunakan beserta beberapa gambar yang menggambarkan program ketika sedang dijalankan.
    Public Class Form1
       

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            cmbkode.Items.Add("SPT")
            cmbkode.Items.Add("SND")
            cmbkode.Items.Add("TST")
            cmbkode.Items.Add("TOP")
            cmbkode.Items.Add("TAS")

            Dim Control As Windows.Forms.Control
            For Each Control In Me.Controls
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "TextBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "RadioButton" Then
                    Control.Enabled = False
                End If
            Next
            Btclear.Enabled = False
        End Sub

        Private Sub cmbkode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbkode.SelectedIndexChanged
            Dim kdbarang, namabarang As String
            Dim harga As Single
            kdbarang = cmbkode.Text

            Select Case kdbarang
                Case "SPT"
                    namabarang = "Sepatu"
                    harga = 200000
                Case "SND"
                    namabarang = "Sandal"
                    harga = 100000
                Case "TST"
                    namabarang = "T-Shirt"
                    harga = 150000
                Case "TOP"
                    namabarang = "Topi"
                    harga = 50000
                Case "TAS"
                    namabarang = "Tas"
                    harga = 250000
                Case Else
                    namabarang = "-"
                    harga = 0
            End Select
            txtnama.Text = namabarang
            txtharga.Text = harga
            Me.radiotunai.Checked = False
            Me.radiokredit.Checked = False
            txtbayar.Clear()
            txtdiskon.Clear()
            txtjumlah.Clear()
            txttotal.Clear()
            txtjumlah.Focus()
        End Sub

        Private Sub txtjumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtjumlah.TextChanged


            If (txtjumlah.Text = "") Then
            Else
                Dim jumlah As Integer
                Try
                    jumlah = Convert.ToInt32(txtjumlah.Text)
                Catch ex As Exception
                    jumlah = 0
                    MsgBox("Jumlah barang harus berupa angka", MsgBoxStyle.Critical, "Peringatan")
                    txtjumlah.Text = ""
                End Try
                    txttotal.Text = Val(txtharga.Text) * jumlah
                    txtbayar.Text = Val(txttotal.Text) - Val(txtdiskon.Text)
                End If
        End Sub

        Private Sub radiotunai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radiotunai.CheckedChanged
            txtdiskon.Text = Val(txttotal.Text) * 10 / 100
            txtbayar.Text = Val(txttotal.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
            txtbayar.Text = Val(txttotal.Text) - Val(txtdiskon.Text)
        End Sub

        Private Sub Btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclear.Click
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
            Me.radiotunai.Checked = False
            Me.radiokredit.Checked = False
            txtbayar.Clear()
            txtdiskon.Clear()
            txtharga.Clear()
            txtjumlah.Clear()
            txtnama.Clear()
            txttotal.Clear()
            cmbkode.Text = ""
           

            Dim Control As Windows.Forms.Control
            For Each Control In Me.Controls
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "TextBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = False
                End If
                If Control.GetType.Name = "RadioButton" Then
                    Control.Enabled = False
                End If
            Next
            Btclear.Enabled = False
            Btisidata.Enabled = True

        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Hand)
            If (MsgBox("Apa Anda yakin untuk menutup aplikasi ini?", vbQuestion + vbYesNo + vbDefaultButton2, "Konfirmasi")) = vbYes Then
                Me.Close()
            End If

        End Sub

        Private Sub Btisidata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btisidata.Click
            My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Exclamation)
            Dim Control As Windows.Forms.Control

            For Each Control In Me.Controls
                If Control.GetType.Name = "ComboBox" Then
                    Control.Enabled = True
                End If
                If Control.GetType.Name = "RadioButton" Then
                    Control.Enabled = True
                End If
            Next
            txtjumlah.Enabled = True
            Btclear.Enabled = True
            Btisidata.Enabled = False


        End Sub
    End Class

    Ketika program pertama kali dijalankan maka akan tampil sebuah form seperti berikut
      Ketika tombol “Isi Data” ditekan maka “Kode Barang”, “Jumlah Barang”, “Cara Beli dan tombol “Clear” akan aktif sementara tombol “Isi Data” justru tidak aktif.

     Ketika tombol “Clear” ditekan maka yang dihasilkan akan sama persis seperti ketika form dimuat
     
Sementara ketika tombol keluar ditekan maka user akan dimintai konfirmasi mengenai niatannya tersebut


Oke, dari penjelasan-penjelasan tersebut setidaknya sudah ada gambaran mengenai modifikasi dari program tersebut dan bisa dikatakan hasil modifikasi tersebut lebih efisien dan efektif dari program sebelumnya. Mungkin itu saja yang bisa saya jelaskan, untuk posting berikutnya saya akan membahas sebuah game puzle yang saya buat sendiri. Sampai jumpa di postingan berikutnya.