Tambahkan kejadian berikut ini, gunakan perulangan :
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
b). Saat ditekan tombol clear sama
dengan saat form dijalankan
Sebelumnya
kita pernah membahas dan membuat program penjualan, sekarang kita modifikasi
program tersebut agar memiliki fungsi seperti perintah diatas.
Langkah-langkah :
1. Pada form kita tambahkan 1 Button
lagi, dan ganti namanya menjadi Isi Data. Seperti tampilan berikut :
2. Selanjutnya double klik pada form 1
lalu masukan coding berikut ini :
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
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
3. Lalu double klik pada button Clear
dan masukan coding berikut ini :
Private Sub btclear_Click(ByVal
sender As System.Object,
ByVal e As System.EventArgs) Handles
btclear.Click
Dim
control As Windows.Forms.Control
For Each control In Me.Controls
control.Enabled = False
btisi.Enabled = True
bttutup.Enabled = True
Next
txtnama.Clear()
txtbayar.Clear()
txtjumlah.Clear()
txtharga.Clear()
txtdiskon.Clear()
txttotal.Clear()
Me.radiotunai.Checked
= False
Me.radiokredit.Checked
= False
cmbkode.Text = ""
End Sub
4. Terakhir kita double klik pada button Isi Data lalu masukan coding
berikut ini :
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 = False
Next
End Sub
End Class
5. Setelah semua selesai lalu kita jalankan program klik Debug – Start
Debugging ( F5 ).
Maka secara otomatis saat
program dijalankan semua fungsi akan mati kecuali tombol Isi Data dan
Tutup,
dan saat tombol Isi Data di klik maka semua fungsi akan aktif kembali, dan
sebaliknya bila kita
mengklik tombol Clear makan semua fungsi akan mati kecuali
tombol Isi Data dan Tutup. Sekian dan
Selamat Mencoba......................
MEMBUAT PUZZLE ANGKA SEDERHANA
Berikut langkah-langkah membuat Puzzle angka
sederhana :
1. Jalankan
Microsoft Visual Basic. Lalu buat projech baru.
2. Pertama
kita inputkan Button sebanyak 9 buah, lalu ganti nama pada masing- masing
button menjadi
berurutan seperti 1,2,3,4,5,6,7,8 dan yang terakhir kita ganti
dengan ( ... ) . lalu atur posisi dan ukuran
masing-masing dengan rapih. Bila
perlu ganti warna dan jenis fontnya sesuai selera. Seperti gambar
dibawah ini :
3. Selanjutnya
kita masukan coding pada Formnya, dengan cara double klik pada Form1 lalu
isikan :
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 = "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
4. Selanjutnya
kita msukan coding pada masing-masing Button.
Berikut codingnya:
Button
1 :
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
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
End Sub
Button
2 :
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
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
End Sub
Button 3 :
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
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
End Sub
Button
4 :
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
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
End Sub
Button
5 :
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
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
End Sub
Button
6 :
Private Sub
Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button6.Click
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
End Sub
Button
7 :
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
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
End Sub
Button
8 :
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
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
End Sub
Button
9 :
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
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
End Sub
5. Setelah
semua selesai selanjutnya kita jalankan programnya dengan klik Debug – Start
Debugging (F5).
Maka tampilannya otomatis akan diacak seperti gambar dibawah
ini :
6. Selanjutnya
kita coba mainkan Puzzlenya.. otomatis apabila kita berhasil mengurutkanya maka
akan
muncul tampilan ucapan : “ SELAMAT
ANDA MENANG “
Sumber :
http://www.gakbakalmati.blogspot.com