Sunday, 28 October 2012

Tugas 3 Pemrogaman Visual (Perulangan)

MODIFIKASI PROGRAM PENJUALAN BARANG DENGAN PERULANGAN

 Soal
  1. Saat form dijalankan : semua isia tiadak aktif, tombol isi data dan tutup aktif, tombol clear tidak aktif
  2. Saat ditekan tombol isi data : kode barang, jumlah barang, cara beli, tombol clear dan tutup aktif, tombol isi data tidak aktif
  3. saat di tekan tombol clear sama dengan saat form dijalankan     


Jawaban NO. 1

Gunakan program yang telah kita buat pada pertemuan ke.2



Pada Form1 tambahkan coding seperti di bawah ini :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

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

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

    End Sub


 Jawaban No.2


Pada button "isi data", isikan kodingnya seperti berikut :
Private Sub btisidata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btisidata.Click
        Dim b As Windows.Forms.Control
        For Each b In Me.Controls
            If b.GetType.Name = "ComboBox" Then
                b.Enabled = True
            ElseIf b.GetType.Name = "RadioButton" Then
                b.Enabled = True
            End If
            btclear.Enabled = True
            bttutup.Enabled = False
            txtjumlah.Enabled = True
            btisidata.Enabled = False

        Next
    End Sub 
 



 Jawaban No.3

Pada button "Clear", tambahkan koding seperti di bawah ini :
Private Sub btclear_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclear.Click
        Dim c As Windows.Forms.Control
        For Each c In Me.Controls
            If c.GetType.Name = "TextBox" Then
                c.Enabled = False
            ElseIf c.GetType.Name = "ComboBox" Then
                c.Enabled = False
            ElseIf c.GetType.Name = "RadioButton" Then
                c.Enabled = False
            End If
            btclear.Enabled = False
            btisidata.Enabled = True
            bttutup.Enabled = True
        Next
        txtbayar.Clear()
        txtdiskon.Clear()
        txtharga.Clear()
        txtjumlah.Clear()
        txtnama.Clear()
        txttotal.Clear()
        Me.radiotunai.Checked = False
        Me.radiokredit.Checked = False
        cmbkode.Text = ""
    End Sub

     
  


Membuat Aplikasi Puzlee
- Buat project baru
- Buat tampilan seperti di bawah ini  


        Ubah pengaturan button pada propeties menjadi di bawah ini :
                  - Pada button 1  1 (angka satu)
-   Pada button 2  2 (angka dua)
-   Pada button 3  3 (angka tiga)
-   Pada button 4  4 (angka empat)
-   Pada button 5  5 (angka lima)
-   Pada button 6  6 (angka enam)
-   Pada button 7  7 (angka tujuh)
-   Pada button 8  8 (angka delapan)
Doble klik pada Form 1, kita akan mengisi koding atau perintah pada form 1, isikan koding seperti berikut :

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  


     Kemudian kita akan memberi perintah untuk semuta button, button1 sampai button9, berikut perintahnya untuk setiap button
a.       Button1

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

b.  Button2

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

c.  Button3

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

d.  Button4

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

e.  Button5

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

f.  Button6

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

g.  Button7

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

h.  Button8

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

i.  Butoon9

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

 

Tampilan setelah berhasil merangkai 





 



No comments:

Post a Comment