riyana's blog: TUGAS PEMROGRAMAN VISUAL 3
Hello Kitty Pink Cherry

Minggu, 28 Oktober 2012

TUGAS PEMROGRAMAN VISUAL 3

Jika ditekan tombol clear semua isian textbox, combobox, radiobutton, dan button tidak aktif.
hasil runningnya adalah sebagai berikut :



Sedangkan coding keseluruhan seperti di bawah ini :

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 = "ComboBox" 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")
            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
        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


Jika ditekan tombol isi data, isian yang aktif antara lain adalah combobox, txtjumlah, dan radio button. Tombol clear dan tutup juga aktif.



Apabila ditekan tombol tutup, maka muncul konfirmasi apakah yakin akan keluar atau tidak?



Aplikasi Permainan Puzzle

Cara memainkan game --> Menyusun angka sesuai urutan dari angka 1 sampai dengan 8. Di dalam pembuatannya saya menggunakan perintah rndcl untuk mengacak angka simetri else if dan pertukaran nilai digunakan untuk mengecek pergeseran angka.


 Jika pemain ingin angka tersebut acak kembali, maka tekan tombol reseat.

Jika pemain dapat menyusun puzzle dengan benar, maka akan muncul ucapan "Selamat"





Di bawah ini adalah coding untuk program di atas :

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
        Dim acak As Integer

        Do
            acak = Rnd() * 8
            bt1.Text = acak
        Loop Until bt1.Text <> "0"
        Do
            acak = Rnd() * 8
            bt2.Text = acak
        Loop Until bt2.Text <> "0" And bt2.Text <> bt1.Text
        Do
            acak = Rnd() * 8
            bt3.Text = acak
        Loop Until bt3.Text <> "0" And bt3.Text <> bt1.Text And bt3.Text <> bt2.Text
        Do
            acak = Rnd() * 8
            bt4.Text = acak
        Loop Until bt4.Text <> "0" And bt4.Text <> bt1.Text And bt4.Text <> bt2.Text And bt4.Text <> bt3.Text
        Do
            acak = Rnd() * 8
            bt5.Text = acak
        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
            acak = Rnd() * 8
            bt6.Text = acak
        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
            acak = Rnd() * 8
            bt7.Text = acak
        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
            acak = Rnd() * 8
            bt8.Text = acak
        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 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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt5.Text = "") Then
            tampung = bt2.Text
            bt2.Text = bt5.Text
            bt5.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt3.Text = "") Then
            tampung = bt2.Text
            bt2.Text = bt3.Text
            bt3.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        End If
    End Sub

    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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt4.Text = "") Then
            tampung = bt1.Text
            bt1.Text = bt4.Text
            bt4.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt6.Text = "") Then
            tampung = bt3.Text
            bt3.Text = bt6.Text
            bt6.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt8.Text = "") Then
            tampung = bt7.Text
            bt7.Text = bt8.Text
            bt8.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        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 (bt6.Text = "") Then
            tampung = bt9.Text
            bt9.Text = bt6.Text
            bt6.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt8.Text = "") Then
            tampung = bt9.Text
            bt9.Text = bt8.Text
            bt8.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt5.Text = "") Then
            tampung = bt4.Text
            bt4.Text = bt5.Text
            bt5.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt7.Text = "") Then
            tampung = bt4.Text
            bt4.Text = bt7.Text
            bt7.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt5.Text = "") Then
            tampung = bt8.Text
            bt8.Text = bt5.Text
            bt5.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt9.Text = "") Then
            tampung = bt8.Text
            bt8.Text = bt9.Text
            bt9.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt5.Text = "") Then
            tampung = bt6.Text
            bt6.Text = bt5.Text
            bt5.Text = tampung
        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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt9.Text = "") Then
            tampung = bt6.Text
            bt6.Text = bt9.Text
            bt9.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        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
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt4.Text = "") Then
            tampung = bt5.Text
            bt5.Text = bt4.Text
            bt4.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt8.Text = "") Then
            tampung = bt5.Text
            bt5.Text = bt8.Text
            bt8.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        ElseIf (bt6.Text = "") Then
            tampung = bt5.Text
            bt5.Text = bt6.Text
            bt6.Text = tampung
            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") Then
                MsgBox("Selamat Anda Berhasil", MsgBoxStyle.Information, "Stattus")
            End If
        End If
    End Sub

    Private Sub btexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btexit.Click
        If MsgBox("Are You Sure Want to Quit?", vbYesNo + vbQuestion + vbDefaultButton1, "quit") = vbYes Then
            Me.Close()
        End If
    End Sub

    Private Sub btreseat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btreseat.Click
        Dim Control As Windows.Forms.Control
        Dim acak As Integer

        Do
            acak = Rnd() * 8
            bt1.Text = acak
        Loop Until bt1.Text <> "0"
        Do
            acak = Rnd() * 8
            bt2.Text = acak
        Loop Until bt2.Text <> "0" And bt2.Text <> bt1.Text
        Do
            acak = Rnd() * 8
            bt3.Text = acak
        Loop Until bt3.Text <> "0" And bt3.Text <> bt1.Text And bt3.Text <> bt2.Text
        Do
            acak = Rnd() * 8
            bt4.Text = acak
        Loop Until bt4.Text <> "0" And bt4.Text <> bt1.Text And bt4.Text <> bt2.Text And bt4.Text <> bt3.Text
        Do
            acak = Rnd() * 8
            bt5.Text = acak
        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
            acak = Rnd() * 8
            bt6.Text = acak
        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
            acak = Rnd() * 8
            bt7.Text = acak
        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
            acak = Rnd() * 8
            bt8.Text = acak
        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
End Class








Tidak ada komentar:

Posting Komentar