image

TUGAS PEMGROGRAMAN VISUAL PRAKTIKUM 3


Tugas 1 (Memodifikasi Program)

Jadi nantinya kita akan memodifikasi program dengan ketentuan :
1. Saat program dijalankan : semua isian data tidak aktif(kode barang, nama barang, sampai total bayar.) dan tombol clear juga tidak aktif, saat program dijalankan hanya tombol Isi data dan tombol tutup yang aktif.
2. Saat ditekan tombol Isi data maka : kodebarang, jumlahbarang, carabeli,dan tombol clear aktif(bisa diisi/ditekan) akan tetapi giliran tombol isi data yang tidak aktif.
3. Saat ditekan tombol Clear, maka ketentuanya sama seperti pada no.1

Pertama ketikan kode dibawah ini dibagian form nya:
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")
        btclear.Enabled = False
        cmbkode.Enabled = False
        txtnama.Enabled = False
        txtharga.Enabled = False
        txtjumlah.Enabled = False
        txttotal.Enabled = False
        txtdiskon.Enabled = False
        txtbayar.Enabled = False
        radiotunai.Enabled = False
        radiokredit.Enabled = False
    End Sub
























hanya tombol "isi data" dan "tutup" yang aktif

Tujuan dari Kode program diatas adalah untuk membuat isian dari kodebarang sampai totalbayar dan tombo clear tidak aktif saat program dijalankan, seperti gambar diatas.
Kedua adalah, tambah satu tombol/button untuk Tombol Isi data dengan text = Isi Data dan name=btisi , dan isi kode programnya seperti seperti dibawah :
Private Sub btisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btisi.Click 
        btclear.Enabled = True
        cmbkode.Enabled = True
        txtjumlah.Enabled = True
        radiotunai.Enabled = True
        radiokredit.Enabled = True
        btisi.Enabled = False
    End Sub
























Maka dengan kode program diatas, tombol tersebut mempunyai fungsi mengaktifkan form kodebarang, jumlahbarang, carabeli,dan mengaktifkan tombol clear, dan juga membuat tombol Isi Data itu sendiri tidak aktif, seperti gambar dibawah.
Dan ini Kode Program dari tombol Clear :
Fungsinya mengosongkan isi dari isian data dan mengembalikan keadaan seperti saat program pertama kali di jalankan

























Private Sub btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclear.Click
        txtdiskon.Clear()
        txtbayar.Clear()
        txtharga.Clear()
        txtnama.Clear()
        txtjumlah.Clear()
        txttotal.Clear()
        cmbkode.Text = ""
        Me.radiokredit.Checked = False
        Me.radiotunai.Checked = False
        btclear.Enabled = False
        cmbkode.Enabled = False
        txtnama.Enabled = False
        txtharga.Enabled = False
        txtjumlah.Enabled = False
        txttotal.Enabled = False
        txtdiskon.Enabled = False
        txtbayar.Enabled = False
        radiotunai.Enabled = False
        radiokredit.Enabled = False
        btisi.Enabled = True
End Sub

Tugas 2 (Membuat Game Puzzle)

Program puzzle
Tampilan program puzzle


















Pertama buat tampilan program seperti gambar diatas, kotak angka 1, 2 sampai 8 dan kotak warna hitam diatas dibuat menggunakan Button.
button1  = 1
button2  = 2
button3  = 3 
button4  = 4
button5 = 5 
button6  = 6
button7  =7 
button8  = 8
button9  = "" (kosonk)
button10  = acak angka
button11  = stop acak
button12  = keluar

Ketikan Kode Program dibawah ini di form :

Public Class Form1
    Dim penampung As String
    Dim warna As Color
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Button11.Enabled = False
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
        Button5.Enabled = False
        Button6.Enabled = False
        Button7.Enabled = False
        Button8.Enabled = False
        Button9.Enabled = False
    End Sub

-Pertama kita pesan Variabel penampung as string.
-kedua kita pesan Variabel warna as color, yang fungsinya sebagai pemberi variabel untuk warna pada button.
-Button1.enabled=false bertujuan untuk menonaktifkan tombol/kotak saat program dijalankan (jadi sebelum ditekan tombol acak maka kotak-kotak angka dan tombol stop acak tidak dapat ditekan)
dan inilah kode programnya dari button1 sampai button 9 :
variabel penampung dan warna sudah dideklarasikan di form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button4.Text = "" Then
            penampung = Button1.Text
            Button1.Text = Button4.Text
            Button4.Text = penampung
            warna = Button1.BackColor
            Button1.BackColor = Button4.BackColor
            Button4.BackColor = warna

        ElseIf Button2.Text = "" Then
            penampung = Button1.Text
            Button1.Text = Button2.Text
            Button2.Text = penampung
            warna = Button1.BackColor
            Button1.BackColor = Button2.BackColor
            Button2.BackColor = warna
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button1.Text = "" Then
            penampung = Button2.Text
            Button2.Text = Button1.Text
            Button1.Text = penampung
            warna = Button2.BackColor
            Button2.BackColor = Button1.BackColor
            Button1.BackColor = warna
        ElseIf Button5.Text = "" Then
            penampung = Button2.Text
            Button2.Text = Button5.Text
            Button5.Text = penampung
            warna = Button2.BackColor
            Button2.BackColor = Button5.BackColor
            Button5.BackColor = warna
        ElseIf Button3.Text = "" Then
            penampung = Button2.Text
            Button2.Text = Button3.Text
            Button3.Text = penampung
            warna = Button2.BackColor
            Button2.BackColor = Button3.BackColor
            Button3.BackColor = warna
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button2.Text = "" Then
            penampung = Button3.Text
            Button3.Text = Button2.Text
            Button2.Text = penampung
            warna = Button3.BackColor
            Button3.BackColor = Button2.BackColor
            Button2.BackColor = warna
        ElseIf Button6.Text = "" Then
            penampung = Button3.Text
            Button3.Text = Button6.Text
            Button6.Text = penampung
            warna = Button3.BackColor
            Button3.BackColor = Button6.BackColor
            Button6.BackColor = warna
        End If
    End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button7.Text = "" Then
            penampung = Button4.Text
            Button4.Text = Button7.Text
            Button7.Text = penampung
            warna = Button4.BackColor
            Button4.BackColor = Button7.BackColor
            Button7.BackColor = warna
        ElseIf Button5.Text = "" Then
            penampung = Button4.Text
            Button4.Text = Button5.Text
            Button5.Text = penampung
            warna = Button4.BackColor
            Button4.BackColor = Button5.BackColor
            Button5.BackColor = warna
        ElseIf Button1.Text = "" Then
            penampung = Button4.Text
            Button4.Text = Button1.Text
            Button1.Text = penampung
            warna = Button4.BackColor
            Button4.BackColor = Button1.BackColor
            Button1.BackColor = warna
        End If
    End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Button8.Text = "" Then
            penampung = Button5.Text
            Button5.Text = Button8.Text
            Button8.Text = penampung
            warna = Button5.BackColor
            Button5.BackColor = Button8.BackColor
            Button8.BackColor = warna
        ElseIf Button6.Text = "" Then
            penampung = Button5.Text
            Button5.Text = Button6.Text
            Button6.Text = penampung
            warna = Button5.BackColor
            Button5.BackColor = Button6.BackColor
            Button6.BackColor = warna
        ElseIf Button4.Text = "" Then
            penampung = Button5.Text
            Button5.Text = Button4.Text
            Button4.Text = penampung
            warna = Button5.BackColor
            Button5.BackColor = Button4.BackColor
            Button4.BackColor = warna
        ElseIf Button2.Text = "" Then
            penampung = Button5.Text
            Button5.Text = Button2.Text
            Button2.Text = penampung
            warna = Button5.BackColor
            Button5.BackColor = Button2.BackColor
            Button2.BackColor = warna
        End If
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Button9.Text = "" Then
            penampung = Button6.Text
            Button6.Text = Button9.Text
            Button9.Text = penampung
            warna = Button6.BackColor
            Button6.BackColor = Button9.BackColor
            Button9.BackColor = warna
        ElseIf Button5.Text = "" Then
            penampung = Button6.Text
            Button6.Text = Button5.Text
            Button5.Text = penampung
            warna = Button6.BackColor
            Button6.BackColor = Button5.BackColor
            Button5.BackColor = warna
        ElseIf Button3.Text = "" Then
            penampung = Button6.Text
            Button6.Text = Button3.Text
            Button3.Text = penampung
            warna = Button6.BackColor
            Button6.BackColor = Button3.BackColor
            Button3.BackColor = warna
        End If
    End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Button8.Text = "" Then
            penampung = Button7.Text
            Button7.Text = Button8.Text
            Button8.Text = penampung
            warna = Button7.BackColor
            Button7.BackColor = Button8.BackColor
            Button8.BackColor = warna
        ElseIf Button4.Text = "" Then
            penampung = Button7.Text
            Button7.Text = Button4.Text
            Button4.Text = penampung
            warna = Button7.BackColor
            Button7.BackColor = Button4.BackColor
            Button4.BackColor = warna
        End If
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Button9.Text = "" Then
            penampung = Button8.Text
            Button8.Text = Button9.Text
            Button9.Text = penampung
            warna = Button8.BackColor
            Button8.BackColor = Button9.BackColor
            Button9.BackColor = warna
        ElseIf Button7.Text = "" Then
            penampung = Button8.Text
            Button8.Text = Button7.Text
            Button7.Text = penampung
            warna = Button8.BackColor
            Button8.BackColor = Button7.BackColor
            Button7.BackColor = warna
        ElseIf Button5.Text = "" Then
            penampung = Button8.Text
            Button8.Text = Button5.Text
            Button5.Text = penampung
            warna = Button8.BackColor
            Button8.BackColor = Button5.BackColor
            Button5.BackColor = warna
        End If
    End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Button8.Text = "" Then
            penampung = Button9.Text
            Button9.Text = Button8.Text
            Button8.Text = penampung
            warna = Button9.BackColor
            Button9.BackColor = Button8.BackColor
            Button8.BackColor = warna
        ElseIf Button6.Text = "" Then
            penampung = Button9.Text
            Button9.Text = Button6.Text
            Button6.Text = penampung
            warna = Button9.BackColor
            Button9.BackColor = Button6.BackColor
            Button6.BackColor = warna

        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 Berhasil Mengurutkan Puzzle ini")
        End If
    End Sub

Apabila Kode program diatas sudah dimasukan disetiap tombol sesuai ketentuanya maka kotak-kotak pada game puzzle ini sudah bisa digerakan sesuai denganketentuan(Saat ditekan tombol yang terletak di dekat tombol kosong/warna hitam maka tombol tersebut akan menempati tombol/kotak kosong/kotak berwarna hitam, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8.)
Membuat Acak Angka :
untuk tombol ini kita butuh satu komponen lagi yaitu toolbox Timer, yang fungsinya untuk mengajak angka-angka secara otomatis dan berkelanjutan dan tidak akan berhenti sampai ditekanya tombol stop.


















Setelah timer di pilih, akan muncul gambar jam/timer kecil dibawah, setelah itu klik gambar jam kecil itu dan masuka kode program dibawah ini(kode program untuk mengacak angka-angka)
langsung saja kita lihat kode programnya :

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim pindah As String

        'satu
        pindah = Button9.Text
        Button9.Text = Button6.Text
        Button6.Text = Button3.Text
        Button3.Text = pindah

        warna = Button9.BackColor
        Button9.BackColor = Button6.BackColor
        Button6.BackColor = Button3.BackColor
        Button3.BackColor = warna

        'dua
        pindah = Button8.Text
        Button8.Text = Button5.Text
        Button5.Text = Button2.Text
        Button2.Text = pindah

        warna = Button8.BackColor
        Button8.BackColor = Button5.BackColor
        Button5.BackColor = Button2.BackColor
        Button2.BackColor = warna

        'tiga
        pindah = Button7.Text
        Button7.Text = Button8.Text
        Button8.Text = Button9.Text
        Button9.Text = pindah

        warna = Button7.BackColor
        Button7.BackColor = Button8.BackColor
        Button8.BackColor = Button9.BackColor
        Button9.BackColor = warna
       
        'empat
        pindah = Button4.Text
        Button4.Text = Button5.Text
        Button5.Text = Button6.Text
        Button6.Text = pindah

        warna = Button4.BackColor
        Button4.BackColor = Button5.BackColor
        Button5.BackColor = Button6.BackColor
        Button6.BackColor = warna
       

        'lima
        pindah = Button7.Text
        Button7.Text = Button4.Text
        Button4.Text = Button1.Text
        Button1.Text = pindah

        warna = Button7.BackColor
        Button7.BackColor = Button4.BackColor
        Button4.BackColor = Button1.BackColor
        Button1.BackColor = warna

    End Sub

     Setelah Kode diatas dimasukan di Timer, sekarang tinggal memasukan kode program untuk mengaktifkan pengacakan angka-angka tersebut melalui tombol Acak Angka.
Masukan kode program dibawah ini di Button10 / tombol acak angka. :

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Timer1.Enabled = True 
        Button1.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = True
        Button5.Enabled = True
        Button6.Enabled = True
        Button7.Enabled = True
        Button8.Enabled = True
        Button9.Enabled = True
        Button10.Enabled = False
        Button11.Enabled = True   
End Sub

Kode Program diatas berfungsi selain untuk mengaktifkan acak Angka(yang kode programnya ada di Timer) juga untuk mengaktifkan tombol / kotak puzzle yang sebelumnya emang dinon aktifkan dan juga berfungsi untuk non aktifkan tombol Acak angka ini sendiri.

















Membuat Tombol Stop Acak

Private Sub Button11_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Button11.Enabled = False
        Timer1.Enabled = False
        Button10.Enabled = True
    End Sub














Finish!!
Progam siap untuk di jalankan..
Semoga bermanfaat bagi semua..amin
TETAP BERJUANG!!!

Go..go…SEMANGAT!!!


0 komentar:

Posting Komentar