Minggu, 11 November 2012

Tugas 3 Pemrograman Visual

1. modifikasi latihan if case


Listing Programnya:

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 kontrol As Windows.Forms.Control
        For Each kontrol In Me.Controls
            If kontrol.GetType.Name = "TextBox" Or kontrol.Name = "ComboBox" Or kontrol.GetType.Name = "RadioButton" Then
                kontrol.Enabled = False
                Btclear.Enabled = False
                Bttutup.Enabled = True
            End If
        Next kontrol
    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbkode.SelectedIndexChanged
        Dim kdbarang, nmbarang As String
        Dim harga As Single
        kdbarang = cmbkode.Text
        Select Case kdbarang
            Case "SPT"
                nmbarang = "Sepatu"
                harga = 200000
            Case "SND"
                nmbarang = "Sandal"
                harga = 100000
            Case "TST"
                nmbarang = "T-Shirt"
                harga = 1500000
            Case "TOP"
                nmbarang = "Topi"
                harga = 500000
            Case Else
                nmbarang = "-"
                harga = 0
        End Select
        txtnama.Text = nmbarang
        txtharga.Text = harga
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtnama.TextChanged
       
    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)
    End Sub
Private Sub Btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclear.Click
    txtbayar.Clear()
        txtharga.Clear()
        txtjumlah.Clear()
        txtnama.Clear()
        txttotal.Clear()
        txtdiskon.Clear()
        Me.radiotunai.Checked = False
        Me.radiokredit.Checked = False
        cmbkode.Text = " "
        For Each kontrol In Me.Controls
            If kontrol.GetType.Name = "TextBox" Or kontrol.GetType.Name = "ComboBox" Or kontrol.GetType.Name = "RadioButton" Then
                kontrol.Enabled = False
                Btclear.Enabled = False
                Bttutup.Enabled = True
                btisi.Enabled = True
            End If
        Next kontrol
    End Sub

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

    Private Sub txtjumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtjumlah.TextChanged
        txttotal.Text = Val(txtharga.Text) * Val(txtjumlah.Text)
        txtbayar.Text = Val(txttotal.Text) - Val(txtdiskon.Text)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        txttotal.Text = Val(txtharga.Text) * Val(txtjumlah.Text)
        txtdiskon.Text = Val(txttotal.Text) * 10 / 100
        If radiotunai.Checked = True Then
            txtbayar.Text = Val(txttotal.Text) - Val(txtdiskon.Text)
        ElseIf radiokredit.Checked = True Then
            txtdiskon.Text = 0
            txtbayar.Text = Val(txttotal.Text)
        End If

    End Sub
    Private Sub txttotal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttotal.TextChanged
        txttotal.Text = Val(txtharga.Text) * Val(txtjumlah.Text)
        txtbayar.Text = Val(txttotal.Text) - Val(txtdiskon.Text)
    End Sub

    Private Sub txtdiskon_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtdiskon.TextChanged
        txtdiskon.Text = Val(txttotal.Text) * 10 / 100
    End Sub

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

    Private Sub btisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btisi.Click
        Dim kontrol As Windows.Forms.Control
        For Each kontrol In Me.Controls
            If kontrol.GetType.Name = "TextBox" Or kontrol.GetType.Name = "ComboBox" Or kontrol.GetType.Name = "RadioButton" Then
                kontrol.Enabled = True
                Btclear.Enabled = True
                Bttutup.Enabled = True
                btisi.Enabled = False
            End If
        Next kontrol
    End Sub
End Class

Hasil setelah di run :
1.Tampilan awal 
2. Setelah tekan masukan data:

3. Lalu kita masukan data sesuai keinginan:


Catatan : Disini saya menambahkan tombol masukan data




2. Program Puzzle

Listing programnya:

Public Class Form1

    Private Sub tb_main_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb_main.Click
        For Each puzzle In Me.GroupBox1.Controls
            If puzzle.GetType.Name = "Button" Then
                puzzle.Enabled = True
                tb_main.Enabled = False
                tb_acak.Enabled = True
            End If
        Next
        Dim swap As String
        swap = bt1.Text
        bt1.Text = bt2.Text
        bt2.Text = swap
        swap = bt2.Text
        bt2.Text = bt3.Text
        bt3.Text = swap
        swap = bt4.Text
        bt4.Text = bt5.Text
        bt5.Text = swap
        swap = bt5.Text
        bt5.Text = bt6.Text
        bt6.Text = swap
        swap = bt6.Text
        bt6.Text = bt7.Text
        bt7.Text = swap
        swap = bt7.Text
        bt7.Text = bt8.Text
        bt8.Text = swap
        swap = btblank.Text
        btblank.Text = bt1.Text
        bt1.Text = swap
        swap = btblank.Text
        btblank.Text = bt4.Text
        bt4.Text = swap
    End Sub

    Private Sub tb_keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb_keluar.Click
        If MsgBox("Berhenti mainnya ?", vbQuestion + vbYesNo + vbDefaultButton2, "Pesan") = vbYes Then Me.Close()
    End Sub

    Private Sub tb_acak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tb_acak.Click
        Dim swap As String
        swap = bt1.Text
        bt1.Text = bt2.Text
        bt2.Text = swap
        swap = bt2.Text
        bt2.Text = bt3.Text
        bt3.Text = swap
        swap = bt4.Text
        bt4.Text = bt5.Text
        bt5.Text = swap
        swap = bt5.Text
        bt5.Text = bt6.Text
        bt6.Text = swap
        swap = bt6.Text
        bt6.Text = bt7.Text
        bt7.Text = swap
        swap = bt7.Text
        bt7.Text = bt8.Text
        bt8.Text = swap
        swap = btblank.Text
        btblank.Text = bt1.Text
        bt1.Text = swap
        swap = btblank.Text
        btblank.Text = bt4.Text
        bt4.Text = swap
    End Sub

    Private Sub bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt1.Click
        Dim swap1 As String
        If bt2.Text = " " Then
            swap1 = bt2.Text
            bt2.Text = bt1.Text
            bt1.Text = swap1
        ElseIf bt4.Text = " " Then
            swap1 = bt4.Text
            bt4.Text = bt1.Text
            bt1.Text = swap1
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt2.Click
        Dim swap2 As String
        If bt1.Text = " " Then
            swap2 = bt1.Text
            bt1.Text = bt2.Text
            bt2.Text = swap2
        ElseIf bt3.Text = " " Then
            swap2 = bt3.Text
            bt3.Text = bt2.Text
            bt2.Text = swap2
        ElseIf bt5.Text = " " Then
            swap2 = bt5.Text
            bt5.Text = bt2.Text
            bt5.Text = swap2
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each kotak In Me.GroupBox1.Controls
            If kotak.GetType.Name = "Button" Then
                kotak.Enabled = True
                tb_acak.Enabled = True
            End If
        Next
    End Sub

    Private Sub bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt3.Click
        Dim swap3 As String
        If bt2.Text = " " Then
            swap3 = bt2.Text
            bt2.Text = bt3.Text
            bt3.Text = swap3
        ElseIf bt6.Text = " " Then
            swap3 = bt6.Text
            bt6.Text = bt3.Text
            bt3.Text = swap3
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt4.Click
        Dim swap4 As String
        If bt1.Text = " " Then
            swap4 = bt1.Text
            bt1.Text = bt4.Text
            bt4.Text = swap4
        ElseIf bt5.Text = " " Then
            swap4 = bt5.Text
            bt5.Text = bt4.Text
            bt4.Text = swap4
        ElseIf bt7.Text = " " Then
            swap4 = bt7.Text
            bt7.Text = bt4.Text
            bt4.Text = swap4
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt5.Click
        Dim swap5 As String
        If bt2.Text = " " Then
            swap5 = bt2.Text
            bt2.Text = bt5.Text
            bt5.Text = swap5
        ElseIf bt4.Text = " " Then
            swap5 = bt4.Text
            bt4.Text = bt5.Text
            bt5.Text = swap5
        ElseIf bt6.Text = " " Then
            swap5 = bt6.Text
            bt6.Text = bt5.Text
            bt5.Text = swap5
        ElseIf bt8.Text = " " Then
            swap5 = bt8.Text
            bt8.Text = bt5.Text
            bt5.Text = swap5
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt6.Click
        Dim swap6 As String
        If bt3.Text = " " Then
            swap6 = bt3.Text
            bt3.Text = bt6.Text
            bt6.Text = swap6
        ElseIf bt5.Text = " " Then
            swap6 = bt5.Text
            bt5.Text = bt6.Text
            bt6.Text = swap6
        ElseIf btblank.Text = " " Then
            swap6 = btblank.Text
            btblank.Text = bt6.Text
            bt6.Text = swap6
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt7.Click
        Dim swap7 As String
        If bt4.Text = " " Then
            swap7 = bt4.Text
            bt4.Text = bt7.Text
            bt7.Text = swap7
        ElseIf bt8.Text = " " Then
            swap7 = bt8.Text
            bt8.Text = bt7.Text
            bt7.Text = swap7
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt8.Click
        Dim swap8 As String
        If bt5.Text = " " Then
            swap8 = bt5.Text
            bt5.Text = bt8.Text
            bt8.Text = swap8
        ElseIf bt7.Text = " " Then
            swap8 = bt7.Text
            bt7.Text = bt8.Text
            bt8.Text = swap8
        ElseIf btblank.Text = " " Then
            swap8 = btblank.Text
            btblank.Text = bt8.Text
            bt8.Text = swap8
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub btblank_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btblank.Click
        Dim swap9 As String
        If bt6.Text = " " Then
            swap9 = bt6.Text
            bt6.Text = btblank.Text
            btblank.Text = swap9
        ElseIf bt8.Text = " " Then
            swap9 = bt8.Text
            bt8.Text = btblank.Text
            btblank.Text = swap9
        End If
        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" And btblank.Text = " " Then
            MsgBox("Berhasil", vbInformation, "Pesan ")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Application.Restart()
    End Sub
End Class

 Setelah selesai, jalankan program :
 
 1.Ketika program dijalankan



2.Kemudian,acak acak susunan angkanya dengan menekan tombol acak:

3.Lalu,susun angka-angkanya sampai seperti  ini  dengan menekan tombol main:




 Mungkin Sekian Postingan dari saya,Terima Kasih...