Memodifikasi program penjualan & Membuat Game Puzzle
MODIFIKASI PROGRAM PENJUALAN
a) Saat form dijalankan : semua isian tidak aktif, tombol isidata dan tutup aktif, tombol clear tidak aktif
b) Saat ditekan tombol isi data : kodebarang, jumlahbarang, cara beli, tombol clear, aktif, tombol isidata tidak aktif
c) Saat ditekan combol clear sama dengan saat form dijalankan
- Tambahkan satu Button untuk program yang kemarin,
Seperti yang dibawah ini :
listing program :
Tambah coding pada form seperti dibawah ini;
Dim control As Windows.Forms.Control
For Each control In Me.Controls
control.Enabled = False
Button3.Enabled = True
Button2.Enabled = True
Next
CmbKodbar.Items.Add("SPT")
CmbKodbar.Items.Add("SND")
CmbKodbar.Items.Add("TST")
CmbKodbar.Items.Add("CLN")
CmbKodbar.Items.Add("TAS")
- Setelah itu edit pada button clear sehinga menjadi seperti dibawah ini;
For Each control In Me.Controls
control.Enabled = False
Button3.Enabled = True
Button2.Enabled = True
Next
TxtNambar.Clear()
TxtHarbar.Clear()
TxtJumbar.Clear()
TxtTotHarg.Clear()
TxtDiskon.Clear()
TxtTotBayr.Clear()
Me.RadioButton1.Checked = False
Me.RadioButton2.Checked = False
CmbKodbar.Text = ""
- terakhir isi button ‘’isi data”;
For Each control In Me.Controls
control.Enabled = True
Button3.Enabled = False
- Next Lalu di Run
semua tidak aktif ,yang aktif hanya isi data & Tutup !
klik button isi data ! lalu akan muncul seperti gambar di bawah ini :
setelah di isi :
setelah di clear akkan kolom akan kosong kembali seperti semula & button yang aktif hanya isi data dan tutup !
seperti gambar di bawah ini :
LISTING PROGRAM PENJUALAN SETELAH DI MODIFIKASI !
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
control.Enabled = False
Button3.Enabled = True
Button2.Enabled = True
Next
CmbKodbar.Items.Add("SPT")
CmbKodbar.Items.Add("SND")
CmbKodbar.Items.Add("TST")
CmbKodbar.Items.Add("CLN")
CmbKodbar.Items.Add("TAS")
End Sub
Private Sub CmbKodbar_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbKodbar.SelectedIndexChanged
Dim Kodebarang, Namabarang As String
Dim Harga As Single
Kodebarang = CmbKodbar.Text
Select Case Kodebarang
Case "SPT"
Namabarang = "Sepatu"
Harga = 100000
Case "SND"
Namabarang = "Sendal"
Harga = 25000
Case "TST"
Namabarang = "T-Shirt"
Harga = 30000
Case "CLN"
Namabarang = "Celana"
Harga = 150000
Case "TAS"
Namabarang = "TAS"
Harga = 90000
Case Else
Namabarang = "-"
Harga = 0
End Select
TxtNambar.Text = Namabarang
TxtHarbar.Text = Harga
End Sub
Private Sub TxtJumbar_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtJumbar.TextChanged
TxtTotHarg.Text = Val(TxtHarbar.Text) * Val(TxtJumbar.Text)
TxtTotBayr.Text = Val(TxtTotHarg.Text) - Val(TxtDiskon.Text)
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
TxtDiskon.Text = Val(TxtTotHarg.Text) * 10 / 100
TxtTotBayr.Text = Val(TxtTotHarg.Text) - Val(TxtDiskon.Text)
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
TxtDiskon.Text = 0
TxtTotBayr.Text = Val(TxtTotHarg.Text) - Val(TxtDiskon.Text)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim control As Windows.Forms.Control
For Each control In Me.Controls
control.Enabled = False
Button3.Enabled = True
Button2.Enabled = True
Next
TxtNambar.Clear()
TxtHarbar.Clear()
TxtJumbar.Clear()
TxtTotHarg.Clear()
TxtDiskon.Clear()
TxtTotBayr.Clear()
Me.RadioButton1.Checked = False
Me.RadioButton2.Checked = False
CmbKodbar.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If MsgBox("Apakah anda ingin keluar ?",
vbYesNo + vbQuestion + vbDefaultButton2, "Keluar") = vbYes Then
End If
Me.Close()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim control As Windows.Forms.Control
For Each control In Me.Controls
control.Enabled = True
Button3.Enabled = False
Next
End Sub
End Class
"TUGAS MEMBUAT GAME PUZLE"
GAME PUZLE :
Desain game puzle di bawah ini dengan menggunakan 9 button :
Pada propertis tiap-tiap button ganti seperti dibawah ini:
Ganti text button1 dengan 1 dan name button1 dengan satu
Ganti text button1 dengan 2 dan name button1 dengan dua
Ganti text button1 dengan 3 dan name button1 dengan tiga
Ganti text button1 dengan 4 dan name button1 dengan empat
Ganti text button1 dengan 5 dan name button1 dengan lima
Ganti text button1 dengan 6 dan name button1 dengan enam
Ganti text button1 dengan 7 dan name button1 dengan tujuh
Ganti text button1 dengan 8 dan name button1 dengan delapan
Ganti text button1 dengan 9 dan name button1 dengan kosong
- Setelah itu masukan coding pada Form1 dengan cara Form1 di klik 2 kali
Adapun codingnya yaitu seperti dibawah ini:
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 dua.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
dua.Text = number
Loop Until dua.Text <> satu.Text
End If
If tiga.Text = dua.Text Or tiga.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
tiga.Text = number
Loop Until tiga.Text <> dua.Text And tiga.Text <> satu.Text
End If
If empat.Text = tiga.Text Or empat.Text = dua.Text Or empat.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
empat.Text = number
Loop Until empat.Text <> tiga.Text And empat.Text <> dua.Text And empat.Text <> satu.Text
End If
If empat.Text = tiga.Text Or empat.Text = dua.Text Or empat.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
empat.Text = number
Loop Until empat.Text <> tiga.Text And empat.Text <> dua.Text And empat.Text <> satu.Text
End If
If lima.Text = empat.Text Or lima.Text = tiga.Text Or lima.Text = dua.Text Or lima.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
lima.Text = number
Loop Until lima.Text <> empat.Text And lima.Text <> tiga.Text And lima.Text <> dua.Text And lima.Text <> satu.Text
End If
If enam.Text = lima.Text Or enam.Text = empat.Text Or enam.Text = tiga.Text Or enam.Text = dua.Text Or enam.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
enam.Text = number
Loop Until enam.Text <> lima.Text And enam.Text <> tiga.Text And enam.Text <> dua.Text And enam.Text <> satu.Text
End If
If tujuh.Text = enam.Text Or tujuh.Text = lima.Text Or tujuh.Text = empat.Text Or tujuh.Text = tiga.Text Or tujuh.Text = dua.Text Or tujuh.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
tujuh.Text = number
Loop Until tujuh.Text <> enam.Text And tujuh.Text <> lima.Text And tujuh.Text <> empat.Text And tujuh.Text <> tiga.Text And tujuh.Text <> dua.Text And tujuh.Text <> satu.Text
End If
If delapan.Text = tujuh.Text Or delapan.Text = enam.Text Or delapan.Text = lima.Text Or delapan.Text = empat.Text Or delapan.Text = tiga.Text Or delapan.Text = dua.Text Or delapan.Text = satu.Text Then
Do
number = rndnumber.Next(1, 9)
delapan.Text = number
Loop Until delapan.Text <> tujuh.Text And delapan.Text <> enam.Text And delapan.Text <> lima.Text And delapan.Text <> empat.Text And delapan.Text <> tiga.Text And delapan.Text <> dua.Text And delapan.Text <> satu.Text
End If
End If
kosong.Text = ""
Next
End Sub
- Kemudian masukan coding untuk tiap-tiap Button, kita mulai dari
BUTTON 1;
If dua.Text = "" Then
dua.Text = satu.Text
satu.Text = ""
ElseIf empat.Text = "" Then
empat.Text = satu.Text
satu.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
End Sub
BUTTON 2;
If satu.Text = "" Then
satu.Text = dua.Text
dua.Text = ""
ElseIf tiga.Text = "" Then
tiga.Text = dua.Text
dua.Text = ""
ElseIf lima.Text = "" Then
lima.Text = dua.Text
dua.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
BUTTON 3;
If dua.Text = "" Then
dua.Text = tiga.Text
tiga.Text = ""
ElseIf enam.Text = "" Then
enam.Text = tiga.Text
tiga.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
BUTTON 4;
If satu.Text = "" Then
satu.Text = empat.Text
empat.Text = ""
ElseIf tujuh.Text = "" Then
tujuh.Text = empat.Text
empat.Text = ""
ElseIf lima.Text = "" Then
lima.Text = empat.Text
empat.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
BUTTON 5;
If dua.Text = "" Then
dua.Text = lima.Text
lima.Text = ""
ElseIf empat.Text = "" Then
empat.Text = lima.Text
lima.Text = ""
ElseIf enam.Text = "" Then
enam.Text = lima.Text
lima.Text = ""
ElseIf delapan.Text = "" Then
delapan.Text = lima.Text
lima.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
BUTTON 6;
If kosong.Text = "" Then
kosong.Text = enam.Text
enam.Text = ""
ElseIf tiga.Text = "" Then
tiga.Text = enam.Text
enam.Text = ""
ElseIf lima.Text = "" Then
lima.Text = enam.Text
enam.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
BUTTON 7;
If empat.Text = "" Then
empat.Text = tujuh.Text
tujuh.Text = ""
ElseIf delapan.Text = "" Then
delapan.Text = tujuh.Text
tujuh.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
BUTTON 8;
If tujuh.Text = "" Then
tujuh.Text = delapan.Text
delapan.Text = ""
ElseIf kosong.Text = "" Then
kosong.Text = delapan.Text
delapan.Text = ""
ElseIf lima.Text = "" Then
lima.Text = delapan.Text
delapan.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
BUTTON KOSONG;
If enam.Text = "" Then
enam.Text = kosong.Text
kosong.Text = ""
ElseIf delapan.Text = "" Then
delapan.Text = kosong.Text
kosong.Text = ""
End If
If satu.Text = "1" And dua.Text = "2" And tiga.Text = "3" And empat.Text = "4" And lima.Text = "5" And enam.Text = "6" And tujuh.Text = "7" And delapan.Text = "8" And kosong.Text = "" Then
MsgBox("Selamat Anda Berhasil")
End If
lalu kita RUN !
hasilnya seperti gambar di bawah ini :
dan siap di mainkan ,jika anda berhasil akan muncul tulisan seperti berikut :
sekian :) selamat mencoba !
Tidak ada komentar:
Posting Komentar