Senin, 12 November 2012

Tugas Memodifikasi Program dan Puzzle

Memodifikasi program Perintah program :

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 tombol clear sama dengan saat form dijalankan

Buatlah program sesuai dengan gambar dibawah ini:


Dengan variabel dibawah ini:
1. TextBox
2. ComboBox
3. RadioBox
4. Button
dengan spesifikasi nama varibel sesuai dengan yang tertera pada gambar diatas.
kemudian isikan coding pada masing-masing variable tersebut:
  • Listing program pada form dengan cara klik 2 kali pada form dan isikan listing programnya seperti yang ada pada dibawah ini:


Public Class Form1
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 = “ComboBox” Then
Control.Enabled = False
End If
If Control.GetType.Name = “TextBox” Then
Control.Enabled = False
End If
If Control.GetType.Name = “RadioButton” Then
Control.Enabled = False
End If
btclear.Enabled = False
btisi.Enabled = True
bttutup.Enabled = True
Next
cmbkode.Items.Add(“SPT”)
cmbkode.Items.Add(“SND”)
cmbkode.Items.Add(“TST”)
cmbkode.Items.Add(“TOP”)
cmbkode.Items.Add(“TAS”)
End Sub
  • Masukan listing program ComboBox dengan cara klik 2 kali pada ComboBox dan isikan listing program berikut ini:
Private Sub cmbkode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbkode.SelectedIndexChanged
Dim kdbarang, namabarang As String
Dim harga As Single
kdbarang = cmbkode.Text
Select Case kdbarang
Case “SPT”
namabarang = “Sepatu”
harga = 200000
Case “SND”
namabarang = “Sandal”
harga = 100000
Case “TST”
namabarang = “T-Shirt”
harga = 150000
Case “TOP”
namabarang = “Topi”
harga = 50000
Case “TAS”
namabarang = “Tas Ransel”
harga = 300000
Case Else
namabarang = “-”
harga = 0
End Select
txtnama.Text = namabarang
txtharga.Text = harga
End Sub

  •      Selanjutnya isikan listing program untuk  TextBox jumlah:
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)
End Sub
  • Listing program yang ada pada masing-masing RadioButton:
  • RadioTunai
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
  • RadioKredit
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
  • Baiklah sekarang kita mlai isikan coding untuk yang ada pada Button:
  • Buttontutup
Private Sub bttutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttutup.Click
Me.Close()
End Sub
  • ButtonHarga
1.     Listing program yang ada pada ButtonHarga:
Private Sub txtharga_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtharga.TextChanged
txttotal.Text = Val(txtharga.Text) * Val(txtjumlah.Text)
End Sub
  • ButtonIsi
Private Sub btisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btisi.Click
Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
Control.Enabled = True
btisi.Enabled = True
Next
End Sub
End Class

Nah setelah selesai dan cobalah jalankan program tersebut maka akan tapilan seperti ini:



LATIHAN 2 – MEMBUAT PUZZLE
Perintah Program :
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

Pertama buatlah variabel yang ada pada gambar dengan spesifikasi seperti dibawah ini:
. menggunakan tombol Button 1-8 dan Button 10 untuk acaknya,
dan susunlah sepeti yang ada pada gambar dibawah ini:


isikan coding dibawah ini dengan klik dua kali pada Form:

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


Kemudian langkah ke dua dengan memasukan coding pada masing-masing Button tersebut satu persatu:
  • ButtonRandom

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)
Button1.Text = number
If Button2.Text = Button1.Text Then
Do
number = rndnumber.Next(1, 10)
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, 10)
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, 10)
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, 10)
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, 10)
Button6.Text = number
Loop Until Button6.Text <> Button5.Text And Button6.Text <> Button4.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, 10)
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, 10)
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
If Button9.Text = Button8.Text Or Button9.Text = Button7.Text Or Button9.Text = Button6.Text Or Button9.Text = Button5.Text Or Button9.Text = Button4.Text Or Button9.Text = Button3.Text Or Button9.Text = Button2.Text Or Button9.Text = Button1.Text Then
Do
number = rndnumber.Next(1, 10)
Button9.Text = number
Loop Until Button9.Text <> Button8.Text And Button9.Text <> Button7.Text And Button9.Text <> Button6.Text And Button9.Text <> Button5.Text And Button9.Text <> Button4.Text And Button9.Text <> Button3.Text And Button9.Text <> Button2.Text And Button9.Text <> Button1.Text
End If
End If
Next
btmulai.Text = “MULAI”
keluar.Text = “KELUAR”
If Button1.Text = “9″ Then
Button1.Text = “”
End If
If Button2.Text = “9″ Then
Button2.Text = “”
End If
If Button3.Text = “9″ Then
Button3.Text = “”
End If
If Button4.Text = “9″ Then
Button4.Text = “”
End If
If Button5.Text = “9″ Then
Button5.Text = “”
End If
If Button6.Text = “9″ Then
Button6.Text = “”
End If
If Button7.Text = “9″ Then
Button7.Text = “”
End If
If Button8.Text = “9″ Then
Button8.Text = “”
End If
If Button9.Text = “9″ Then
Button9.Text = “”
End If
End Sub
Private Sub Berhasil()
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
MessageBox.Show(“Selamat Anda Berhasil”)
End If
End Sub
Private Sub btmulai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmulai.Click
Kode_randomisasi()
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
If MsgBox(“Kamu yakin ingin keluar dari game ini?”, vbInformation + vbYesNo + vbDefaultButton2, “KELUAR”) = vbYes Then
Me.Close()
End If
End Sub
  • Button1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button2.Text = “” Then
Button2.Text = Button1.Text
Button1.Text = “”
ElseIf Button4.Text = “” Then
Button4.Text = Button1.Text
Button1.Text = “”
End If
End Sub
  • Button2

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
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
End Sub
  • Button3

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button2.Text = “” Then
Button2.Text = Button3.Text
Button3.Text = “”
ElseIf Button6.Text = “” Then
Button6.Text = Button3.Text
Button3.Text = “”
End If
End Sub
  • Button4

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button1.Text = “” Then
Button1.Text = Button4.Text
Button4.Text = “”
ElseIf Button5.Text = “” Then
Button5.Text = Button4.Text
Button4.Text = “”
ElseIf Button7.Text = “” Then
Button7.Text = Button4.Text
Button4.Text = “”
End If
End Sub
  • Button5

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
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
End Sub
  • Button6

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button3.Text = “” Then
Button3.Text = Button6.Text
Button6.Text = “”
ElseIf Button5.Text = “” Then
Button5.Text = Button6.Text
Button6.Text = “”
ElseIf Button9.Text = “” Then
Button9.Text = Button6.Text
Button6.Text = “”
End If
End Sub
  • Button7

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Button4.Text = “” Then
Button4.Text = Button7.Text
Button7.Text = “”
ElseIf Button8.Text = “” Then
Button8.Text = Button7.Text
Button7.Text = “”
End If
End Sub
  • Button8

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Button7.Text = “” Then
Button7.Text = Button8.Text
Button8.Text = “”
ElseIf Button5.Text = “” Then
Button5.Text = Button8.Text
Button8.Text = “”
ElseIf Button9.Text = “” Then
Button9.Text = Button8.Text
Button8.Text = “”
End If
End Sub
  • Button9

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If Button6.Text = “” Then
Button6.Text = Button9.Text
Button9.Text = “”
ElseIf Button8.Text = “” Then
Button8.Text = Button9.Text
Button9.Text = “”
End If
Berhasil()
End Sub

maka ketika program dijalankan dan ButtonRandom ditekan akan menampilkan seperti ini:

 Saat akan keluar maka akan muncul seprti peringatan dibawah ini:


semoga bermanfaat bagi anda.....

1 komentar:

rendiardiansa mengatakan...

TOKO GAME Grosir Menawarkan Harga Promo stok terbatas
PS 3 Super Slim 500 GB + PES 2014 (30041)
Paket : Console PS 3 Super Slim 500 GB + Bluray Game Original PES 2014, Manual Book, Kabel AV, Kabel Power, 1 Dualshock3 Wireless Controller.
Note : Ada WiFi Adapter Internal, Bisa main Game PS3 semua region, 2 Port USB Versi 2.0, Power Supply 220V, Barang Baru dan ORIGINAL bukan Refurbish.
Price : Rp 1.650.000,-

PS 3 Super Slim 500 GB + PES 2014 + Joystick Wireless KW (30042)
Paket : Console PS 3 Super Slim 500 GB + Bluray Game Original PES 2014 + Joystick Wireless KW, Manual Book, Kabel AV, Kabel Power, 1 Dualshock3 Wireless Controller.
Note : Ada WiFi Adapter Internal, Bisa main Game PS3 semua region, 2 Port USB Versi 2.0, Power Supply 220V, Barang Baru dan ORIGINAL bukan Refurbish.
Price : Rp 1.850.000,-

PS 3 Super Slim 250 GB + E3 ODE + HD External 500 GB (Isi +/- 40 Game) + HDMI + BD Original (30087)

Paket : Console PS 3 Super Slim 250 GB + E3 ODE + HD External 500 GB (Isi +/- 40 Game ada PES 2014, GTA 5, dll) + HDMI + BD Original untuk Pancingan, Manual Book, Kabel AV, Kabel Power, 1 Dualshock3 Wireless Controller.
Note : Ada WiFi Adapter Internal, Bisa main Game PS3 semua region, 2 Port USB Versi 2.0, Power Supply 220V, Barang Baru dan ORIGINAL bukan Refurbish.
Christmas SALE : Rp 2.600.000,-

PS 3 Super Slim 250 GB + E3 ODE + HD External 500 GB (Isi +/- 40 Game) + HDMI + BD Original + Joystick Wireless KW (30088)

Paket : Console PS 3 Super Slim 250 GB + E3 ODE + HD External 500 GB (Isi +/- 40 Game ada PES 2014, GTA 5, dll) + HDMI + BD Original untuk Pancingan, Manual Book, Kabel AV, Kabel Power, 1 Dualshock3 Wireless Controller, + Joystick Wireless KW.
Note : Ada WiFi Adapter Internal, Bisa main Game PS3 semua region, 2 Port USB Versi 2.0, Power Supply 220V, Barang Baru dan ORIGINAL bukan Refurbish.
Christmas SALE : Rp 2.700.000,-

PS 3 Move + Camera + Navigator (30007)
Paket : PS 3 Move Motion Controller, Camera PS 3, Navigator.
Price : Rp 550.000,-
PS 3 Move + Camera (30008)
Paket : PS 3 Move Motion Controller, Camera PS 3.
Price : Rp 400.000,-
XBox One + Kinect (x0023)
Price : Rp 6.200.000,-

XBOX Gitar Rockband 3 (x0014)
Note : Gitar Rockband 3.
Price : Rp 1.200.000,-

Xbox 360 Slim 4 GB JTAG / RGH + Kinect + HD 500 GB (Full Game) (x0004)
Note : bisa main game copy.
Paket :
1 Console Xbox 360 Slim 4 GB JTAG / RGH Warna Hitam, 1 Wireless Controller, Kinect Sensor, Hardisk External 500 GB (Full Game +/- 80 Game), 1 Game Original, Composite AV Cable, Internal Wifi Capability.
Price : Rp 2.600.000,-

PlayStation 4 (30043)
Price : Rp 4.300.000,-
Toko Game Grosir
Mangga Dua Square Lt GF Blok C No 37-40 Jakarta Barat
Hp.0823-1333-2548

Posting Komentar