Saturday, October 27, 2012

Tgas Visual Basic 3

TUGAS 3



Kode sebelum di modifikasi:

Public Class Form1
 Private Sub cmb_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As   System.EventArgs) Handles cmb.SelectedIndexChanged
      
        Dim kdbarang, nmbarang As String
        Dim harga As Single
        kdbarang = cmb.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 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 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

        txtbayar.Clear()
        txtjumlah.Clear()
        txtdiskon.Clear()
        txtnama.Clear()
        txttotal.Clear()
        txtharga.Clear()
    End Sub

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

End Class

Ketentuan :

1.      Saat form dijalankan : Semua isian tidak aktif ,tombol isi data dan tutup aktif, sedangkan tombol clear  tidak aktif.
2.      Saat ditekan isi data : kode barang, jumlah barang, cara beli, tombol clear aktif, tombol isi data tidak aktif.
3.      Saat ditekan tombol clear sama dengan saat form dijalankan.

Proses:
1.      Tuliskan kode di form

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cmb.Enabled = False
        txtdiskon.Enabled = False
        txtharga.Enabled = False
        txtbayar.Enabled = False
        txtnama.Enabled = False
        txttotal.Enabled = False
        txtjumlah.Enabled = False
        btclear.Enabled = False
        radiotunai.Enabled = False
        radiokredit.Enabled = False
        GroupBox1.Enabled = True

 End Sub

2.      Tuliskan kode di button isi data

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btisidata.Click
     
        GroupBox1.Enabled = False
        cmb.Enabled = True
        txtjumlah.Enabled = True
        radiokredit.Enabled = True
        radiotunai.Enabled = True
        btclear.Enabled = True

    End Sub

3.      Tambahkan kode di button clear

 cmb.Enabled = False
        txtdiskon.Enabled = False
        txtharga.Enabled = False
        txtbayar.Enabled = False
        txtnama.Enabled = False
        txttotal.Enabled = False
        txtjumlah.Enabled = False
        btclear.Enabled = False
        radiotunai.Enabled = False
        radiokredit.Enabled = False
        GroupBox1.Enabled = True

Hasil  Modifikasi

Klik Dedugging atau F5,setelah itu akan muncul program berikut ini:     
    
                   


Kemudian klik tombol isi data , isi data pembeliannya
                   
Untuk menghapus klik tombol clear ,setelah itu akan kembali seperti semula




B.     Membuat Puzzle

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

Proses pembuatan :
1.      Buka Microsoft Visual Basic 2010
2.      Klik new project
3.      Pada Installed Templates pilih windows, Windows Form  Application
4.      Kemudian tulis nama projek di Name dan Ok
5.      Buat desain form dengan ketentuan seperti berikut
·         Buat 9 button
      button 1 > tulis angka 1
      button  2> tulis angka2
      button  3> tulis angka 3
      button  4> tulis angka  4
      button  5> tulis angka 5
      button  6> tulis angka 6
      button  7> tulis angka  7
      button  8> tulis angka 9
      button 9 > kosong
·          Setelah pengurutan selesai akan muncul pesan "Selamat Anda Berhasil"
6.      Tuliskan kode di  Form

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
            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

    End Sub


7.      Tuliskan kode di button 1 sampai 9 dengan ketentuan sebagai berikut
·         Button 1

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

·          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

·         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

·           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

·         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

·         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

·         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

·         Button9

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


 Hasil Modifikasi