Halaman

Selamat datang di GO blog semoga apa yang ada di blog ini bermanfaat bagi pembaca

Jumat, 26 Oktober 2012

Membuat puzzle dan Memodifikasi


       MEMODIFIKASI PROGRAM PENJUALAN BARANG

         Saat form dijalankan : semua isian tidak aktif, tombol isidata dan tutup aktif, tombol clear tidak aktif
         Saat ditekan tombol isi data : kodebarang, jumlahbarang, cara beli, tombol clear, aktif, tombol    isidata tidak aktif
         Saat ditekan combol clear sama dengan saat form dijalankan.
                                                                                         
Program penjualan yang pernah di buat,  modifikasi program tersebut dengan ketentuan diatas, dengan menghapus textbox kembalian, textbox jumlah bayar, dan tombol kembalian.
        Saat form dijalankan : semua isian tidak aktif, tombol isidata dan tutup aktif, tombol clear tidak aktif, tampilan seperti berikut :



Scriptnya sebagai berikut:
    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 = "GroupBox" Then control.Enabled = True
            btisidata.Enabled = True
            BtHapus.Enabled = False
            BtKeluar.Enabled = True
            txtnabar.Enabled = False
            txthabar.Enabled = False
            cmbkode.Enabled = False
            txttotbar.Enabled = False
            txtjumbar.Enabled = False
            txtdiskon.Enabled = False
            txttohar.Enabled = False
            RadioButton1.Enabled = False
            RadioButton2.Enabled = False
        Next
    End Sub


           Saat ditekan tombol isi data : kodebarang, jumlahbarang, cara beli, tombol clear, aktif, tombol isidata tidak aktif



    Private Sub btisidata_Click_1(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 = "GroupBox" Then control.Enabled = True
            btisidata.Enabled = False
            BtHapus.Enabled = True
            BtKeluar.Enabled = True
            txtnabar.Enabled = False
            txthabar.Enabled = False
            cmbkode.Enabled = True
            txttotbar.Enabled = False
            txtjumbar.Enabled = True
            txtdiskon.Enabled = False
            txttohar.Enabled = False
            RadioButton1.Enabled = True
            RadioButton2.Enabled = True
        Next
    End Sub

          Saat ditekan combol clear sama dengan saat form dijalankan.



    Private Sub BtHapus_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtHapus.Click
        txtdiskon.Clear()
        txthabar.Clear()
        txtnabar.Clear()
        txttohar.Clear()
        txttotbar.Clear()
        txtjumbar.Clear()

        Me.RadioButton1.Checked = False
        Me.RadioButton2.Checked = False
        cmbkode.Text = ""

        For Each control In Me.Controls
            If control.GetType.Name = "GroupBox" Then control.Enabled = True
            btisidata.Enabled = True
            BtHapus.Enabled = False
            BtKeluar.Enabled = True
            txtnabar.Enabled = False
            txthabar.Enabled = False
            cmbkode.Enabled = False
            txttotbar.Enabled = False
            txtjumbar.Enabled = False
            txtdiskon.Enabled = False
            txttohar.Enabled = False
            RadioButton1.Enabled = False
            RadioButton2.Enabled = False
        Next
    End Sub



2.      Membuat puzzle angka

Pertama buat tampilan pada form 1 seperti berikut :



Isikan script atau code dibawah pada form 1
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

Kemudian isikan script berikut pada setiap Button
    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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        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("Congratulation,,, !! you win ")
        End If

    End Sub
End Class.

Tidak ada komentar:

Posting Komentar