Minggu, 28 Oktober 2012

Tugas 3 Pemrograman Visual

soal 1

modifikasi program pada pertemuan sebelumnya :



1.Saat form dijalankan : semua isian tidak aktif, tombol isidata dan tutup aktif, tombol clear tidak aktif
2.Saat ditekan tombol isi data : kodebarang, jumlahbarang, cara beli, tombol clear, aktif, tombol isidata tidak aktif
3.Saat ditekan combol clear sama dengan saat form dijalankan

Jawab


1.semua isian tidak aktif dikarnakan pada bagian tersebut terdapat perintah :
  cmbkode.Enabled = False
        txtnama.Enabled = False
        txtharga.Enabled = False
        txtjumlah.Enabled = False
        txttotal.Enabled = False
        Radiotunai.Enabled = False
        Radiokridit.Enabled = False
        txtdiskon.Enabled = False
        txtbayar.Enabled = False
        Btclear.Enabled = False
2.pada saat kita menekan tombol Isi data maka perintah yg di berikan kodebarang,   jumlahbarang, cara beli, tombol clear, aktif, tombol isidata tidak aktif.hal ni dikarnakan terdapat perintah:
cmbkode.Enabled = True
        txtjumlah.Enabled = True
        Radiotunai.Enabled = True
        Radiokridit.Enabled = True
        Btclear.Enabled = True
        Btisi.Enabled = False










3.Saat di tekan tombol clear program menjadi seperti semula dikarnakan terdapat perintah sebagai berikut:
  cmbkode.Enabled = True
        txtnama.Enabled = True
        txtharga.Enabled = True
        txtjumlah.Enabled = True
        txttotal.Enabled = True
        Radiotunai.Enabled = True
        Radiokridit.Enabled = True
        txtdiskon.Enabled = True
        txtbayar.Enabled = True
        Btclear.Enabled = True
        Btisi.Enabled = True













soal 2

Buatlah permainan puzzle sederhana
skenario sebagai berikut :
1.Saat form dijalankan posisi angka acak
2.Saat ditekan tombol yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombol kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8
3.Saat angka sudah tersusun tampilkan pesan selamat anda berhasil
Jawab


Langkah - langkah :


1.       Ubah Text

-   Pada button 1 => 1 (angka satu)
-   Pada button 2 => 2 (angka dua)
-   Pada button 3 => 3 (angka tiga)
-   Pada button 4 => 4 (angka empat)
-   Pada button 5 => 5 (angka lima)
-   Pada button 6 => 6 (angka enam)
-   Pada button 7 => 7 (angka tujuh)
-   Pada button 8 => 8 (angka delapan)

2.       Doble klik pada Form 1, kita akan mengisi koding atau perintah pada form 1, isikan koding seperti berikut :
 
Dim control As Windows.Forms.Control
ForEach control InMe.Controls
If control.GetType.Name = "Button"Then
Dim rndnumber AsRandom
Dim number AsInteger
                rndnumber = NewRandom
                number = rndnumber.Next(1, 9)
                control.Text = number
If Button2.Text = Button1.Text Then
Do
                number = rndnumber.Next(1, 9)
                Button2.Text = number
LoopUntil Button2.Text <> Button1.Text
EndIf
If Button3.Text = Button2.Text Or Button3.Text = Button1.Text Then
Do
                number = rndnumber.Next(1, 9)
                Button3.Text = number
LoopUntil Button3.Text <> Button2.Text And Button3.Text <> Button1.Text
EndIf
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
LoopUntil Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text
EndIf
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
LoopUntil Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text
EndIf
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
LoopUntil Button5.Text <> Button4.Text And Button5.Text <> Button3.Text And Button5.Text <> Button2.Text And Button5.Text <> Button1.Text
EndIf
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
LoopUntil Button6.Text <> Button5.Text And Button6.Text <> Button3.Text And Button6.Text <> Button2.Text And Button6.Text <> Button1.Text
EndIf
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
LoopUntil 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
EndIf
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
LoopUntil 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
EndIf
EndIf
                Button9.Text = ""
Next

3.       Kemudian kita akan memberi perintah untuk semuta button, button1 sampai button9, berikut perintahnya untuk setiap button
a.       Button1
If Button2.Text = ""Then
            Button2.Text = Button1.Text
            Button1.Text = ""
ElseIf Button4.Text = ""Then
            Button4.Text = Button1.Text
            Button1.Text = ""
EndIf
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")
EndIf
b.  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 = ""
EndIf
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")
EndIf
c.  Button3
If Button2.Text = ""Then
            Button2.Text = Button3.Text
            Button3.Text = ""
ElseIf Button6.Text = ""Then
            Button6.Text = Button3.Text
            Button3.Text = ""
EndIf
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")
EndIf
d.  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 = ""
EndIf
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")
EndIf
e.  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 = ""
EndIf
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")
EndIf
f.  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 = ""
EndIf
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")
EndIf
g.  Button7
If Button4.Text = ""Then
            Button4.Text = Button7.Text
            Button7.Text = ""
ElseIf Button8.Text = ""Then
            Button8.Text = Button7.Text
            Button7.Text = ""
EndIf
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")
EndIf
h.  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 = ""
EndIf
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")
EndIf
i.  Butoon9
If Button6.Text = ""Then
            Button6.Text = Button9.Text
            Button9.Text = ""
ElseIf Button8.Text = ""Then
            Button8.Text = Button9.Text
            Button9.Text = ""
EndIf
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")
EndIf

 


dan hasilnya sebagai berikut :

















 untuk melihat hasilnya tekan f5 ,,
jika berhasil menyelesaikan permainan maka akan ada tanda seperti bi bawah ini


0 komentar:

Posting Komentar