Sabtu, 27 Oktober 2012

TUGAS PEMROGRAMAN VISUAL 3


Haii Guys..!!

Program yang pertama akan saya tampilkan adalah modifikasi dari Tugas 2 ,jadi

1.  Saat form dijalankan : semua isian tidak aktif, tombol isidata dan tutup aktif, tombol clear tidak aktif
2.  Saat ditekan tombol isi data : kodebarang, jumlahbarang, cara beli, tombol clear, aktif, tombol isi data     tidak aktif
3.  Saat ditekan combol clear sama dengan saat form dijalankan

Berikut tampilan program pada saat dijalankan :




Apabila pada saat menekan tombol isi data ,form akan aktif ,sedangkan tombol isi data tidak aktif. Seperti gambar dibawah ini  :




Dan ketika menekan tombol clear ,form akan kembali seperti pada saat pertama kali dijalankan :




Berikut kodingnya - CEKIDOT :

Public Class Form1
    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
            a.Enabled = False
            Button2.Enabled = True
            Button1.Enabled = True
        Next
       

        cmbkode.Items.Add(“SPT”)
        cmbkode.Items.Add(“SND”)
        cmbkode.Items.Add(“TST”)
        cmbkode.Items.Add(“TOP”)
        cmbkode.Items.Add(“TAS”)

    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 = 200000
            
            Case Else
                namabarang = “_”
                harga = 0

        End Select
        Txtnama.Text = namabarang
        Txtharga.Text = harga
        Txtharga.Text = Format(harga, “#,#”)
    End Sub

    Private Sub Txtjumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txtjumlah.TextChanged
        Dim total As Single

        Txttotal.Text = Val(Txtharga.Text) * Val(Txtjumlah.Text)
        Txtbayar.Text = Val(Txttotal.Text) – Val(Txtdiskon.Text)
        Txttotal.Text = Format(total, “#,#”)
    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
        Dim a As Windows.Forms.Control

        For Each a In Me.Controls
            a.Enabled = False
            Button2.Enabled = True
            Button1.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

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As Windows.Forms.Control

        For Each a In Me.Controls
            a.Enabled = True
            Button1.Enabled = False
        Next
    End Sub
End Class


Program kedua adalah Puzzle

1.  Saat form dijalankan posisi angka acak
2.  Saat ditekan tombol yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombol kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8
3.  Saat angka sudah tersusun tampilkan pesan selamat anda berhasil

Ketika form dijalankan, posisi angka acak :



Saat ditekan tombol yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombol kosong seperti gambar dibawah ini :





Saat angka sudah tersusun tampilkan pesan selamat anda berhasil !!



Berikut kodingnya - CEKIDOT :

Public Class Form1
    Dim angka(0 To 8) As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       
        Dim Control As Windows.Forms.Control
        Dim number As Integer
        Dim rndnumber As Random
        rndnumber = New Random

        For Each Control In Me.Controls
            If Control.GetType.Name = “Button” Then

        number = rndnumber.Next(1, 9)
            Control.Text = number

            End If

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

            If btn1.Text = btn3.Text Or btn2.Text = btn3.Text Then
                Do
                    number = rndnumber.Next(1, 9)
                    btn3.Text = number
                Loop Until btn1.Text <> btn3.Text And btn2.Text <> btn3.Text
            End If

            If btn1.Text = btn4.Text Or btn2.Text = btn4.Text Or btn3.Text = btn4.Text Then
                Do
                    number = rndnumber.Next(1, 9)
                    btn4.Text = number
                Loop Until btn1.Text <> btn4.Text And btn2.Text <> btn4.Text And btn3.Text <> btn4.Text
            End If

            If btn1.Text = btn5.Text Or btn2.Text = btn5.Text Or btn3.Text = btn5.Text Or btn4.Text = btn5.Text Then
                Do
                    number = rndnumber.Next(1, 9)
                    btn5.Text = number
                Loop Until btn1.Text <> btn5.Text And btn2.Text <> btn5.Text And btn3.Text <> btn5.Text And btn4.Text <> btn5.Text
            End If

            If btn1.Text = btn6.Text Or btn2.Text = btn6.Text Or btn3.Text = btn6.Text Or btn4.Text = btn6.Text Or btn5.Text = btn6.Text Then
                Do
                    number = rndnumber.Next(1, 9)
                    btn6.Text = number
                Loop Until btn1.Text <> btn6.Text And btn2.Text <> btn6.Text And btn3.Text <> btn6.Text And btn4.Text <> btn6.Text And btn5.Text <> btn6.Text
            End If

            If btn1.Text = btn7.Text Or btn2.Text = btn7.Text Or btn3.Text = btn7.Text Or btn4.Text = btn7.Text Or btn5.Text = btn7.Text Or btn6.Text = btn7.Text Then
                Do
                    number = rndnumber.Next(1, 9)
                    btn7.Text = number
                Loop Until btn1.Text <> btn7.Text And btn2.Text <> btn7.Text And btn3.Text <> btn7.Text And btn4.Text <> btn7.Text And btn5.Text <> btn7.Text And btn6.Text <> btn7.Text
            End If

            If btn1.Text = btn8.Text Or btn2.Text = btn8.Text Or btn3.Text = btn8.Text Or btn4.Text = btn8.Text Or btn5.Text = btn8.Text Or btn6.Text = btn8.Text Or btn7.Text = btn8.Text Then
                Do
                    number = rndnumber.Next(1, 9)
                    btn8.Text = number
                Loop Until btn1.Text <> btn8.Text And btn2.Text <> btn8.Text And btn3.Text <> btn8.Text And btn4.Text <> btn8.Text And btn5.Text <> btn8.Text And btn6.Text <> btn8.Text And btn7.Text <> btn8.Text
            End If

            If btn9.Text <> “” Then
                btn9.Text = “”
            End If
        Next
    End Sub

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        If btn2.Text = “” Then
            btn2.Text = btn1.Text
            btn1.Text = “”
        ElseIf btn4.Text = “” Then
            btn4.Text = btn1.Text
            btn1.Text = “”
        Else
            btn1.Text = btn1.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
        If btn1.Text = “” Then
            btn1.Text = btn2.Text
            btn2.Text = “”
        ElseIf btn3.Text = “” Then
            btn3.Text = btn2.Text
            btn2.Text = “”
        ElseIf btn5.Text = “” Then
            btn5.Text = btn2.Text
            btn2.Text = “”
        Else
            btn2.Text = btn2.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
        If btn2.Text = “” Then
            btn2.Text = btn3.Text
            btn3.Text = “”
        ElseIf btn6.Text = “” Then
            btn6.Text = btn3.Text
            btn3.Text = “”
        Else
            btn3.Text = btn3.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
        If btn1.Text = “” Then
            btn1.Text = btn4.Text
            btn4.Text = “”
        ElseIf btn7.Text = “” Then
            btn7.Text = btn4.Text
            btn4.Text = “”
        ElseIf btn5.Text = “” Then
            btn5.Text = btn4.Text
            btn4.Text = “”
        Else
            btn4.Text = btn4.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
        If btn2.Text = “” Then
            btn2.Text = btn5.Text
            btn5.Text = “”
        ElseIf btn4.Text = “” Then
            btn4.Text = btn5.Text
            btn5.Text = “”
        ElseIf btn8.Text = “” Then
            btn8.Text = btn5.Text
            btn5.Text = “”
        ElseIf btn6.Text = “” Then
            btn6.Text = btn5.Text
            btn5.Text = “”
        Else
            btn5.Text = btn5.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
        If btn9.Text = “” Then
            btn9.Text = btn6.Text
            btn6.Text = “”
        ElseIf btn3.Text = “” Then
            btn3.Text = btn6.Text
            btn6.Text = “”
        ElseIf btn5.Text = “” Then
            btn5.Text = btn6.Text
            btn6.Text = “”
        Else
            btn6.Text = btn6.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
        If btn8.Text = “” Then
            btn8.Text = btn7.Text
            btn7.Text = “”
        ElseIf btn4.Text = “” Then
            btn4.Text = btn7.Text
            btn7.Text = “”
        Else
            btn7.Text = btn7.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)

        End If
    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
        If btn9.Text = “” Then
            btn9.Text = btn8.Text
            btn8.Text = “”
        ElseIf btn7.Text = “” Then
            btn7.Text = btn8.Text
            btn8.Text = “”
        ElseIf btn5.Text = “” Then
            btn5.Text = btn8.Text
            btn8.Text = “”
        Else
            btn8.Text = btn8.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
        If btn8.Text = “” Then
            btn8.Text = btn9.Text
            btn9.Text = “”
        ElseIf btn6.Text = “” Then
            btn6.Text = btn9.Text
            btn9.Text = “”
        Else
            btn9.Text = btn9.Text
        End If

        If btn1.Text = “1″ And btn2.Text = “2″ And btn3.Text = “3″ And btn4.Text = “4″ And btn5.Text = “5″ And btn6.Text = “6″ And btn7.Text = “7″ And btn8.Text = “8″ And btn9.Text = “” Then
            MessageBox.Show(“SELAMAT ANDA BERHASIL”)
        End If
    End Sub

   
End Class




SEMOGA  BERMANFAAT