Sabtu, 27 Oktober 2012

Tugas Pemrograman Visual 3

Soal 1
Memodifikasi program if dan case pada tugas 2

Kali ini terdapat fitur tambahan, yaitu tombol Isi Data. Dimana saat program dijalankan seluruh fungsi kontrol tidak aktif kecuali tombol Isi Data dan Tutup. Dan apa bila tombol Isi Data di tekan, seluruh fungsi program aktif kecuali tombol Isi Data.

dan ini Codingnya ;


    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
            Control.Enabled = False
                btisidata.Enabled = True
                bttutup.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 ComboBox1_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 = 500000
            Case "TAS"
                namabarang = "Tas"
                harga = 130000
            Case Else
                namabarang = "-"
                harga = 0
        End Select

        txtnama.Text = namabarang
        txtharga.Text = harga



    End Sub

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

        txttotalharga.Text = Val(txtharga.Text) * Val(txtjumlah.Text)
        txtbayar.Text = Val(txttotalharga.Text) - Val(txtdiskon.Text)

    End Sub

    Private Sub tunai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tunai.CheckedChanged
        txtdiskon.Text = Val(txttotalharga.Text) * 10 / 100
        txtbayar.Text = Val(txttotalharga.Text) - Val(txtdiskon.Text)

    End Sub

    Private Sub kredit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kredit.CheckedChanged
        txtdiskon.Text = 0
        txtbayar.Text = Val(txttotalharga.Text) - Val(txtdiskon.Text)


    End Sub

    Private Sub btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclear.Click
        txtbayar.Clear()
        txtharga.Clear()
        txtdiskon.Clear()
        txtjumlah.Clear()
        txtnama.Clear()
        txttotalharga.Clear()
        Me.tunai.Checked = False
        Me.kredit.Checked = False
        cmbkode.Text = ""
        Dim Control As Windows.Forms.Control
        For Each Control In Me.Controls
            Control.Enabled = False
            btisidata.Enabled = True
            bttutup.Enabled = True
        Next

    End Sub

    Private Sub bttutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttutup.Click
        If MsgBox("Anda yakin akan keluar?", vbYesNo + vbQuestion + vbDefaultButton2, "Keluar") = vbYes Then Me.Close()
    End Sub

    Private Sub txtharga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtharga.TextChanged
        txttotalharga.Text = Val(txtharga.Text) * Val(txtjumlah.Text)


    End Sub

    Private Sub ttlharga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttotalharga.TextChanged
        txttotalharga.Text = Val(txtharga.Text) * Val(txtjumlah.Text)
    End Sub

    Private Sub Button1_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
            Control.Enabled = True
        Next
        For Each Control In Me.Controls
            btisidata.Enabled = False
        Next

    End Sub
End Class

Selesai dah....

Lanjut ke Soal 2 Puzzle sederhana

Tujuannya membuat Puzzle sederhana yang saat di jalankan puzzle sudah teracak, dan saat semua puzzle tersusun dengan benar, keluar pesan Congratulation Bro ^_^ .

Langkah-langkahnya adalah  buat design pada form seperti ini


Lalu isikan Codingnya seperti di bawah ini

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim acak As Integer
        acak = Rnd() * 10
        bt1.Text = acak
        bt2.Text = acak - 2
        bt3.Text = acak - 5
        bt4.Text = acak - 3
        bt5.Text = acak + 1
        bt6.Text = acak - 1
        bt7.Text = acak - 6
        bt8.Text = acak - 4
    End Sub

    Private Sub pesan()
        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("Congratulation Bro ^_^")
        End If
    End Sub

    Private Sub bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt1.Click
        If bt4.Visible = False Then
            bt1.Visible = False
            bt4.Visible = True
            bt4.Text = bt1.Text
        ElseIf bt2.Visible = False Then
            bt1.Visible = False
            bt2.Visible = True
            bt2.Text = bt1.Text
        End If
        pesan()

    End Sub

    Private Sub bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt2.Click
        If bt1.Visible = False Then
            bt2.Visible = False
            bt1.Visible = True
            bt1.Text = bt2.Text
        ElseIf bt5.Visible = False Then
            bt2.Visible = False
            bt5.Visible = True
            bt5.Text = bt2.Text
        ElseIf bt3.Visible = False Then
            bt2.Visible = False
            bt3.Visible = True
            bt3.Text = bt2.Text
        End If
        pesan()

    End Sub

    Private Sub bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt3.Click
        If bt6.Visible = False Then
            bt3.Visible = False
            bt6.Visible = True
            bt6.Text = bt3.Text
        ElseIf bt2.Visible = False Then
            bt3.Visible = False
            bt2.Visible = True
            bt2.Text = bt3.Text
        End If
        pesan()

    End Sub

    Private Sub bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt4.Click
        If bt1.Visible = False Then
            bt4.Visible = False
            bt1.Visible = True
            bt1.Text = bt4.Text
        ElseIf bt7.Visible = False Then
            bt4.Visible = False
            bt7.Visible = True
            bt7.Text = bt4.Text
        ElseIf bt5.Visible = False Then
            bt4.Visible = False
            bt5.Visible = True
            bt5.Text = bt4.Text
        End If
        pesan()

    End Sub

    Private Sub bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt5.Click
        If bt2.Visible = False Then
            bt5.Visible = False
            bt2.Visible = True
            bt2.Text = bt5.Text
        ElseIf bt4.Visible = False Then
            bt5.Visible = False
            bt4.Visible = True
            bt4.Text = bt5.Text
        ElseIf bt6.Visible = False Then
            bt5.Visible = False
            bt6.Visible = True
            bt6.Text = bt5.Text
        ElseIf bt8.Visible = False Then
            bt5.Visible = False
            bt8.Visible = True
            bt8.Text = bt5.Text
        End If
        pesan()

    End Sub

    Private Sub bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt6.Click
        If bt3.Visible = False Then
            bt6.Visible = False
            bt3.Visible = True
            bt3.Text = bt6.Text
        ElseIf bt.Visible = False Then
            bt6.Visible = False
            bt.Visible = True
            bt.Text = bt6.Text
        ElseIf bt5.Visible = False Then
            bt6.Visible = False
            bt5.Visible = True
            bt5.Text = bt6.Text
        End If
        pesan()

    End Sub

    Private Sub bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt7.Click
        If bt4.Visible = False Then
            bt7.Visible = False
            bt4.Visible = True
            bt4.Text = bt7.Text
        ElseIf bt8.Visible = False Then
            bt7.Visible = False
            bt8.Visible = True
            bt8.Text = bt7.Text
        End If
        pesan()

    End Sub

    Private Sub bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt8.Click
        If bt.Visible = False Then
            bt8.Visible = False
            bt.Visible = True
            bt.Text = bt8.Text
        ElseIf bt7.Visible = False Then
            bt8.Visible = False
            bt7.Visible = True
            bt7.Text = bt8.Text
        ElseIf bt5.Visible = False Then
            bt8.Visible = False
            bt5.Visible = True
            bt5.Text = bt8.Text
        End If
        pesan()

    End Sub

    Private Sub bt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt.Click
        If bt6.Visible = False Then
            bt.Visible = False
            bt6.Visible = True
            bt6.Text = bt.Text
        ElseIf bt8.Visible = False Then
            bt.Visible = False
            bt8.Visible = True
            bt8.Text = bt.Text
        End If
        pesan()

    End Sub
End Class


Nah,,,, setelah di jalankan maka akan terjadi hal-hal menakjubkan seperti ini...

Kemudian mainkan puzzlenya seperti ini...

Dan seperti ini...

jika sudah berhasil menyusunnya ... keajaiban pun terjadi seperti ini...

Selamat Mencoba ^_^





Tidak ada komentar:

Posting Komentar