Minggu, 28 Oktober 2012

Tugas Pem Visual 3

Tugas Pemrograman Visual 3
Soal 1
1. Tampilan Awal

2. Tampilan ketika dijalankan semua isian tidak aktif dan tombol isi data dan tutup aktif sedangkan clear tidak aktif
3. Ketika menekan tombol isi data isian kode barang, jumlah barang, cara beli, dan tombol clear aktif sedangkan tombol isi datanya tidak aktif




4. Ketika tombol clear ditekan keadaan kembali sperti awal program dijalankan



Source Kode dibawah ini
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add("SPT")
        ComboBox1.Items.Add("SND")
        ComboBox1.Items.Add("TST")
        ComboBox1.Items.Add("TOP")
        ComboBox1.Items.Add("TAS")
        TextDiskon.Enabled = False
        TextHargaBarang.Enabled = False
        TextNamaBarang.Enabled = False
        TextJmlBarang.Enabled = False
        TextTotBayar.Enabled = False
        TextTotHarga.Enabled = False
        RadKredit.Enabled = False
        RadTunai.Enabled = False
        BtClear.Enabled = False
        ComboBox1.Enabled = False

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Dim kodebarang, namabarang As String
        Dim harga As Single
        kodebarang = ComboBox1.Text
        Select Case kodebarang
            Case "SPT"
                namabarang = "Sepatu"
                harga = 200000
            Case "SND"
                namabarang = "Sendal"
                harga = 100000
            Case "TST"
                namabarang = "T-Shirt"
                harga = 150000
            Case "TOP"
                namabarang = "Topi"
                harga = 50000
            Case Else
                namabarang = "-"
                harga = 0

        End Select
        TextNamaBarang.Text = namabarang
        TextHargaBarang.Text = harga

    End Sub

    Private Sub TextJmlBarang_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextJmlBarang.TextChanged
        TextTotHarga.Text = Val(TextHargaBarang.Text) * Val(TextJmlBarang.Text)
    End Sub

    Private Sub RadTunai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadTunai.CheckedChanged
        TextDiskon.Text = Val(TextTotHarga.Text) * 10 / 100
        TextTotBayar.Text = Val(TextTotHarga.Text) - Val(TextDiskon.Text)
    End Sub

    Private Sub RadKredit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadKredit.CheckedChanged
        TextDiskon.Text = 0
        TextTotBayar.Text = Val(TextTotHarga.Text) - Val(TextDiskon.Text)
    End Sub

    Private Sub BtTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtTutup.Click
        End
    End Sub

    Private Sub BtClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtClear.Click
        TextDiskon.Text = ""
        TextHargaBarang.Text = ""
        TextNamaBarang.Text = ""
        TextJmlBarang.Text = ""
        TextJmlBarang.Enabled = False
        TextTotBayar.Text = ""
        TextDiskon.Enabled = False
        TextTotHarga.Text = ""
        RadKredit.Enabled = False
        RadKredit.Checked = False
        RadTunai.Enabled = False
        RadTunai.Checked = False
        ComboBox1.Enabled = False
        ComboBox1.Text = ""
        BtIsiData.Enabled = True
        BtClear.Enabled = False
    End Sub

    Private Sub BtIsiData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtIsiData.Click
        ComboBox1.Enabled = True
        TextJmlBarang.Enabled = True
        RadKredit.Enabled = True
        RadTunai.Enabled = True
        BtClear.Enabled = True
        BtIsiData.Enabled = False
    End Sub
End Class



Soal 2 Game Puzzle
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Kode_randomisasi()
    End Sub

    Private Sub Kode_randomisasi()
        Dim control As Windows.Forms.Control
        For Each control In Me.Controls
            If control.GetType.Name = "Button" Then
                Dim rndnumber As Random
                rndnumber = New Random
                Dim number As Integer
                control.Text = number

                number = rndnumber.Next(1, 10)
                Bt1.Text = number

                If Bt2.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt2.Text = number
                    Loop Until Bt2.Text <> Bt1.Text
                End If

                If Bt3.Text = Bt2.Text Or Bt3.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt3.Text = number
                    Loop Until Bt3.Text <> Bt2.Text And Bt3.Text <> Bt1.Text
                End If

                If Bt4.Text = Bt3.Text Or Bt4.Text = Bt2.Text Or Bt4.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt4.Text = number
                    Loop Until Bt4.Text <> Bt3.Text And Bt4.Text <> Bt2.Text And Bt4.Text <> Bt1.Text
                End If

                If Bt5.Text = Bt4.Text Or Bt5.Text = Bt3.Text Or Bt5.Text = Bt2.Text Or Bt5.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt5.Text = number
                    Loop Until Bt5.Text <> Bt4.Text And Bt5.Text <> Bt3.Text And Bt5.Text <> Bt2.Text And Bt5.Text <> Bt1.Text
                End If

                If Bt6.Text = Bt5.Text Or Bt6.Text = Bt4.Text Or Bt6.Text = Bt3.Text Or Bt6.Text = Bt2.Text Or Bt6.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt6.Text = number
                    Loop Until Bt6.Text <> Bt5.Text And Bt6.Text <> Bt4.Text And Bt6.Text <> Bt3.Text And Bt6.Text <> Bt2.Text And Bt6.Text <> Bt1.Text
                End If

                If Bt7.Text = Bt6.Text Or Bt7.Text = Bt5.Text Or Bt7.Text = Bt4.Text Or Bt7.Text = Bt3.Text Or Bt7.Text = Bt2.Text Or Bt7.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt7.Text = number
                    Loop Until Bt7.Text <> Bt6.Text And Bt7.Text <> Bt5.Text And Bt7.Text <> Bt4.Text And Bt7.Text <> Bt3.Text And Bt7.Text <> Bt2.Text And Bt7.Text <> Bt1.Text
                End If

                If Bt8.Text = Bt7.Text Or Bt8.Text = Bt6.Text Or Bt8.Text = Bt5.Text Or Bt8.Text = Bt4.Text Or Bt8.Text = Bt3.Text Or Bt8.Text = Bt2.Text Or Bt8.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt8.Text = number
                    Loop Until Bt8.Text <> Bt7.Text And Bt8.Text <> Bt6.Text And Bt8.Text <> Bt5.Text And Bt8.Text <> Bt4.Text And Bt8.Text <> Bt3.Text And Bt8.Text <> Bt2.Text And Bt8.Text <> Bt1.Text
                End If

                If Bt9.Text = Bt8.Text Or Bt9.Text = Bt7.Text Or Bt9.Text = Bt6.Text Or Bt9.Text = Bt5.Text Or Bt9.Text = Bt4.Text Or Bt9.Text = Bt3.Text Or Bt9.Text = Bt2.Text Or Bt9.Text = Bt1.Text Then
                    Do
                        number = rndnumber.Next(1, 10)
                        Bt9.Text = number
                    Loop Until Bt9.Text <> Bt8.Text And Bt9.Text <> Bt7.Text And Bt9.Text <> Bt6.Text And Bt9.Text <> Bt5.Text And Bt9.Text <> Bt4.Text And Bt9.Text <> Bt3.Text And Bt9.Text <> Bt2.Text And Bt9.Text <> Bt1.Text
                End If
            End If
        Next

        Btacak.Text = "Acak Angka"

        If Bt1.Text = "9" Then
            Bt1.Text = ""
        End If
        If Bt2.Text = "9" Then
            Bt2.Text = ""
        End If
        If Bt3.Text = "9" Then
            Bt3.Text = ""
        End If
        If Bt4.Text = "9" Then
            Bt4.Text = ""
        End If
        If Bt5.Text = "9" Then
            Bt5.Text = ""
        End If
        If Bt6.Text = "9" Then
            Bt6.Text = ""
        End If
        If Bt7.Text = "9" Then
            Bt7.Text = ""
        End If
        If Bt8.Text = "9" Then
            Bt8.Text = ""
        End If
        If Bt9.Text = "9" Then
            Bt9.Text = ""
        End If

    End Sub

    Private Sub Bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt1.Click
        If Bt2.Text = "" Then
            Bt2.Text = Bt1.Text
            Bt1.Text = ""
        ElseIf Bt4.Text = "" Then
            Bt4.Text = Bt1.Text
            Bt1.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt2.Click
        If Bt1.Text = "" Then
            Bt1.Text = Bt2.Text
            Bt2.Text = ""
        ElseIf Bt3.Text = "" Then
            Bt3.Text = Bt2.Text
            Bt2.Text = ""
        ElseIf Bt5.Text = "" Then
            Bt5.Text = Bt2.Text
            Bt2.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt3.Click
        If Bt2.Text = "" Then
            Bt2.Text = Bt3.Text
            Bt3.Text = ""
        ElseIf Bt6.Text = "" Then
            Bt6.Text = Bt3.Text
            Bt3.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt4.Click
        If Bt1.Text = "" Then
            Bt1.Text = Bt4.Text
            Bt4.Text = ""
        ElseIf Bt5.Text = "" Then
            Bt5.Text = Bt4.Text
            Bt4.Text = ""
        ElseIf Bt7.Text = "" Then
            Bt7.Text = Bt4.Text
            Bt4.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt5.Click
        If Bt2.Text = "" Then
            Bt2.Text = Bt5.Text
            Bt5.Text = ""
        ElseIf Bt4.Text = "" Then
            Bt4.Text = Bt5.Text
            Bt5.Text = ""
        ElseIf Bt6.Text = "" Then
            Bt6.Text = Bt5.Text
            Bt5.Text = ""
        ElseIf Bt8.Text = "" Then
            Bt8.Text = Bt5.Text
            Bt5.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt6.Click
        If Bt3.Text = "" Then
            Bt3.Text = Bt6.Text
            Bt6.Text = ""
        ElseIf Bt5.Text = "" Then
            Bt5.Text = Bt6.Text
            Bt6.Text = ""
        ElseIf Bt9.Text = "" Then
            Bt9.Text = Bt6.Text
            Bt6.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt7.Click
        If Bt4.Text = "" Then
            Bt4.Text = Bt7.Text
            Bt7.Text = ""
        ElseIf Bt8.Text = "" Then
            Bt8.Text = Bt7.Text
            Bt7.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt8.Click
        If Bt5.Text = "" Then
            Bt5.Text = Bt8.Text
            Bt8.Text = ""
        ElseIf Bt7.Text = "" Then
            Bt7.Text = Bt8.Text
            Bt8.Text = ""
        ElseIf Bt9.Text = "" Then
            Bt9.Text = Bt8.Text
            Bt8.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt9.Click
        If Bt6.Text = "" Then
            Bt6.Text = Bt9.Text
            Bt9.Text = ""
        ElseIf Bt8.Text = "" Then
            Bt8.Text = Bt9.Text
            Bt9.Text = ""
        End If
        Berhasil()
    End Sub

    Private Sub Berhasil()
        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 Bt9.Text = "" Then
            MessageBox.Show("Selamat Anda Berhasil")
        End If
    End Sub

    Private Sub Btacak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btacak.Click
        Kode_randomisasi()
    End Sub

End Class

 
Berikut hasilnya:
Saat program baru dijalankan maka nomor pun langsung teracak secara otomatis
Ketika user sudah menyelesaikan urutan yang benar maka secara otomatis muncul pesan pop out "Selamat Anda Berhasil". dan permainan berahir. apabila ingin bermain kembali user  pun bisa menggunakan tombol Acak Angka di pojok kanan bawah untuk mengacak puzzle kembali

Minggu, 21 Oktober 2012

Tugas 2 Pemrograman Visual

Jawaban Latihan 1 soal No. 3

  1. Karena variabel alamat nya ada 2.
  2. Variabel nama pada Button1 bersifat local dan tidak dideklarasikan pada Button2. Sehingga nama pada Button2 diambil dari pendeklarasian Modul yaitu “Nandang Hermanto”. Sedangkan alamat sudah dideklarasikan yaitu berupa const sehingga pada Button1 dan Button2 akan bernilai sama, yaitu Kuningan.
  3.  Karena pada Button1 umur dideklarasikan sebagai Dim, sedangkan pada Button2 umur dideklarasikan sebagai Static
  4. Form2 Option Explisit Off. Ini berarti Form2 hanya membaca data dari Modul,  yaitu :Nama           : Nandang Hermanto
    Alamat        : Purwokerto
    Umur           : 17
Jawaban Latihan 2 If dan Case
Analisa Program :
1.         Sudah dimodifikasi dengan :
-          mengubah background form menjadi warna biru langit
-          Font diperbesar dengan ukuran 9 dan ditebalkan
2.         Pada Select Case belum ada data untuk kode “TAS” dengan nama “Tas”, maka penulis tambahkan.
3.         Ketika user mengisi Jumlah Barang, maka pada Total Bayar akan langsung terisi nominal angka meskipun Cara Beli belum dipilih.
Ini karena ada kode program yang berlebihan, sehingga pada modifikasi ini penulis hilangkan.
Private Sub txtjmlbarang_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtjmlbarang.TextChanged
txttotharga.Text = Val(txthrgbarang.Text) * Val(txtjmlbarang.Text)
txttotBayar.Text = Val(txttotharga.Text) * Val(txtDiskon.Text)
End Sub
4.         Tambahkan property “read only” pada text Total Harga, Diskon, dan Total Bayar. Ini dilakukan agar hasil tidak bisa diubah oleh user.

Berikut Koding Program seutuhnya :
Public Class Form1
    Private Sub cmbKode_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 = 150000
            Case "TOP"
                nmbarang = "Topi"
                harga = 50000
            Case "TAS"
                nmbarang = "Tas"
                harga = 300000
            Case Else
                nmbarang = "-"
                harga = 0
        End Select
        txtnmbarang.Text = nmbarang
        txthrgbarang.Text = harga
    End Sub

    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")
    End Sub

    Private Sub txttotharga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txttotharga.TextChanged
        txttotharga.Text = Val(txthrgbarang.Text) * Val(txtjmlbarang.Text)
    End Sub

    Private Sub txtjmlbarang_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtjmlbarang.TextChanged
        txttotharga.Text = Val(txthrgbarang.Text) * Val(txtjmlbarang.Text)
    End Sub

    Private Sub optTunai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optTunai.CheckedChanged
        txtDiskon.Text = Val(txttotharga.Text) * 10 / 100
        txtTotBayar.Text = Val(txttotharga.Text) - Val(txtDiskon.Text)
    End Sub

    Private Sub optKredit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optKredit.CheckedChanged
        txtDiskon.Text = 0
        txtTotBayar.Text = Val(txttotharga.Text)
    End Sub

    Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
        txtDiskon.Clear()
        txthrgbarang.Clear()
        txtjmlbarang.Clear()
        txtnmbarang.Clear()
        txtTotBayar.Clear()
        txttotharga.Clear()
        optKredit.Checked = False
        optTunai.Checked = False
        cmbKode.Text = ""
    End Sub

    Private Sub cmdTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTutup.Click
        Close()
    End Sub
End Class