pada tugas 2 kemarin tampilannya adalah seperti dibawah ini :
tampilan hasil modifikasinya terlihat seperti dibawah ini :
dengan ketentuan seperti dibawah ini :
1
1. Saat form dijalankan : semua isian tidak aktif,
tombol isi data dan tutup aktif, dan tombol clear tidak aktif.
2
2. Saat ditekan tombol isi data : kode barang,
jumlah barang, cara beli, tombol clear dan tombol tutup aktif, tombol isi data.
3
3. Saat ditekan tombol clear sama saat dengan saat
form dijalankan.
Untuk cara pembuatan modifikasinya langsung aja ya :
1. Tambahkan tombol isi data
2. Pada properties, atur tag untuk combobox1,textbox jumlah barang dan cara beli (tunai & kredit) misalnya "a". kemudian atur juga tag untuk textbox nama barang,harga barang,total harga,total bayar,dan diskon misalnya "b".
3. Double klik pada form kemudian tuliskan kode program seperti dibawah 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
If control.Tag = "a" Or control.Tag = "b" Then
control.Enabled = False
End If
btclear.Enabled = False
isi.Enabled = True
bttutup.Enabled = True
Next
4. Double klik pada tombol Isi Data, tuliskan kode program berikut :
Private Sub isi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles isi.Click
Dim control As Windows.Forms.Control
For Each control In Me.Controls
'control.Enabled = True
If control.Tag = "a" Then
control.Enabled = True
End If
isi.Enabled = False
btclear.Enabled = True
Next
End Sub
5. Double klik pada tombol clear, tambahkan kode program berikut :
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
btclear.Enabled = False
isi.Enabled = True
bttutup.Enabled = True
Next
End Sub
Nah itu penjelasan singkat tentang modifikasi yang penulis buat. Sekarang kita lanjutkan program selanjutnya yaitu Program Puzzle.
Untuk cara pembuatan modifikasinya langsung aja ya :
1. Tambahkan tombol isi data
2. Pada properties, atur tag untuk combobox1,textbox jumlah barang dan cara beli (tunai & kredit) misalnya "a". kemudian atur juga tag untuk textbox nama barang,harga barang,total harga,total bayar,dan diskon misalnya "b".
3. Double klik pada form kemudian tuliskan kode program seperti dibawah 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
If control.Tag = "a" Or control.Tag = "b" Then
control.Enabled = False
End If
btclear.Enabled = False
isi.Enabled = True
bttutup.Enabled = True
Next
4. Double klik pada tombol Isi Data, tuliskan kode program berikut :
Private Sub isi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles isi.Click
Dim control As Windows.Forms.Control
For Each control In Me.Controls
'control.Enabled = True
If control.Tag = "a" Then
control.Enabled = True
End If
isi.Enabled = False
btclear.Enabled = True
Next
End Sub
5. Double klik pada tombol clear, tambahkan kode program berikut :
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
btclear.Enabled = False
isi.Enabled = True
bttutup.Enabled = True
Next
End Sub
Nah itu penjelasan singkat tentang modifikasi yang penulis buat. Sekarang kita lanjutkan program selanjutnya yaitu Program Puzzle.
PUZZLE
Untuk ketentuannya :
1. Saat form dijalankan posisi angka dalam keadaan acak. Tapi penulis mengabaikan aturan ini karena penulis menghendaki untuk mengacak lebih dulu.
2. saat ditekan tombol yang terletak didekat tombol kosong, maka tombol tersebut akan menempati tombol tersebut, begitu seterusnya hingga angka tersusun 1 sampai 8.
3. Ketika angka sudah tersusun 1 sampai 8 maka akan muncul pesan "Selamat, Anda Berhasil !".
Penjelasan programnya ada di bawah ini :
1. Buat tampilam form seperti diatas.
2. Tambahkan 2 tombol acak dan stop
kode programnya :
Public Class Form1
Dim acak, acak2, acak3, acak4, acak5, acak6, acak7, acak8, acak9 As Integer
Dim smt As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
End Sub
Private Sub mulai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mulai.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
acak = Rnd() * 8
acak2 = Rnd() * 8
acak3 = Rnd() * 8
acak4 = Rnd() * 8
acak5 = Rnd() * 8
acak6 = Rnd() * 8
acak7 = Rnd() * 8
acak8 = Rnd() * 8
satu.Text = acak
dua.Text = acak2
tiga.Text = acak3
empat.Text = acak4
lima.Text = acak5
enam.Text = acak6
tujuh.Text = acak7
delapan.Text = acak8
End Sub
Private Sub delapan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delapan.Click
If st.Text = "" Then
smt = delapan.Text
delapan.Text = st.Text
st.Text = smt
ElseIf tujuh.Text = "" Then
smt = tujuh.Text
tujuh.Text = delapan.Text
delapan.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = delapan.Text
delapan.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub st_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles st.Click
If enam.Text = "" Then
smt = enam.Text
enam.Text = st.Text
st.Text = smt
ElseIf delapan.Text = "" Then
smt = delapan.Text
delapan.Text = st.Text
st.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub lima_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lima.Click
If dua.Text = "" Then
smt = dua.Text
dua.Text = lima.Text
lima.Text = smt
ElseIf empat.Text = "" Then
smt = empat.Text
empat.Text = lima.Text
lima.Text = smt
ElseIf enam.Text = "" Then
smt = enam.Text
enam.Text = lima.Text
lima.Text = smt
ElseIf delapan.Text = "" Then
smt = delapan.Text
delapan.Text = lima.Text
lima.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub enam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enam.Click
If tiga.Text = "" Then
smt = tiga.Text
tiga.Text = enam.Text
enam.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = enam.Text
enam.Text = smt
ElseIf st.Text = "" Then
smt = st.Text
st.Text = enam.Text
enam.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub tujuh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tujuh.Click
If empat.Text = "" Then
smt = empat.Text
empat.Text = tujuh.Text
tujuh.Text = smt
ElseIf delapan.Text = "" Then
smt = delapan.Text
delapan.Text = tujuh.Text
tujuh.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub empat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles empat.Click
If satu.Text = "" Then
smt = satu.Text
satu.Text = empat.Text
empat.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = empat.Text
empat.Text = smt
ElseIf tujuh.Text = "" Then
smt = tujuh.Text
tujuh.Text = empat.Text
empat.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub satu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles satu.Click
If empat.Text = "" Then
smt = empat.Text
empat.Text = satu.Text
satu.Text = smt
ElseIf dua.Text = "" Then
smt = dua.Text
dua.Text = satu.Text
satu.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub dua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dua.Click
If satu.Text = "" Then
smt = satu.Text
satu.Text = dua.Text
dua.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = dua.Text
dua.Text = smt
ElseIf tiga.Text = "" Then
smt = tiga.Text
tiga.Text = dua.Text
dua.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub tiga_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tiga.Click
If dua.Text = "" Then
smt = dua.Text
dua.Text = tiga.Text
tiga.Text = smt
ElseIf enam.Text = "" Then
smt = enam.Text
enam.Text = tiga.Text
tiga.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub henti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles henti.Click
Timer1.Stop()
satu.Text = "5"
dua.Text = "6"
tiga.Text = "8"
empat.Text = "2"
lima.Text = "1"
enam.Text = "4"
tujuh.Text = "3"
delapan.Text = "7"
st.Text = ""
End Sub
End Class
Dim acak, acak2, acak3, acak4, acak5, acak6, acak7, acak8, acak9 As Integer
Dim smt As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
End Sub
Private Sub mulai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mulai.Click
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
acak = Rnd() * 8
acak2 = Rnd() * 8
acak3 = Rnd() * 8
acak4 = Rnd() * 8
acak5 = Rnd() * 8
acak6 = Rnd() * 8
acak7 = Rnd() * 8
acak8 = Rnd() * 8
satu.Text = acak
dua.Text = acak2
tiga.Text = acak3
empat.Text = acak4
lima.Text = acak5
enam.Text = acak6
tujuh.Text = acak7
delapan.Text = acak8
End Sub
Private Sub delapan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delapan.Click
If st.Text = "" Then
smt = delapan.Text
delapan.Text = st.Text
st.Text = smt
ElseIf tujuh.Text = "" Then
smt = tujuh.Text
tujuh.Text = delapan.Text
delapan.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = delapan.Text
delapan.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub st_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles st.Click
If enam.Text = "" Then
smt = enam.Text
enam.Text = st.Text
st.Text = smt
ElseIf delapan.Text = "" Then
smt = delapan.Text
delapan.Text = st.Text
st.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub lima_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lima.Click
If dua.Text = "" Then
smt = dua.Text
dua.Text = lima.Text
lima.Text = smt
ElseIf empat.Text = "" Then
smt = empat.Text
empat.Text = lima.Text
lima.Text = smt
ElseIf enam.Text = "" Then
smt = enam.Text
enam.Text = lima.Text
lima.Text = smt
ElseIf delapan.Text = "" Then
smt = delapan.Text
delapan.Text = lima.Text
lima.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub enam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enam.Click
If tiga.Text = "" Then
smt = tiga.Text
tiga.Text = enam.Text
enam.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = enam.Text
enam.Text = smt
ElseIf st.Text = "" Then
smt = st.Text
st.Text = enam.Text
enam.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub tujuh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tujuh.Click
If empat.Text = "" Then
smt = empat.Text
empat.Text = tujuh.Text
tujuh.Text = smt
ElseIf delapan.Text = "" Then
smt = delapan.Text
delapan.Text = tujuh.Text
tujuh.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub empat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles empat.Click
If satu.Text = "" Then
smt = satu.Text
satu.Text = empat.Text
empat.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = empat.Text
empat.Text = smt
ElseIf tujuh.Text = "" Then
smt = tujuh.Text
tujuh.Text = empat.Text
empat.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub satu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles satu.Click
If empat.Text = "" Then
smt = empat.Text
empat.Text = satu.Text
satu.Text = smt
ElseIf dua.Text = "" Then
smt = dua.Text
dua.Text = satu.Text
satu.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub dua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dua.Click
If satu.Text = "" Then
smt = satu.Text
satu.Text = dua.Text
dua.Text = smt
ElseIf lima.Text = "" Then
smt = lima.Text
lima.Text = dua.Text
dua.Text = smt
ElseIf tiga.Text = "" Then
smt = tiga.Text
tiga.Text = dua.Text
dua.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub tiga_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tiga.Click
If dua.Text = "" Then
smt = dua.Text
dua.Text = tiga.Text
tiga.Text = smt
ElseIf enam.Text = "" Then
smt = enam.Text
enam.Text = tiga.Text
tiga.Text = smt
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" Then
MsgBox("Selamat, Anda Berhasil !")
End If
End Sub
Private Sub henti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles henti.Click
Timer1.Stop()
satu.Text = "5"
dua.Text = "6"
tiga.Text = "8"
empat.Text = "2"
lima.Text = "1"
enam.Text = "4"
tujuh.Text = "3"
delapan.Text = "7"
st.Text = ""
End Sub
End Class
Nah sekiranya itu yang bisa penulis postkan hari ini semoga bermanfaat untuk semua. Sampai jumpa diprogram selanjutnyaaa..... :)
Terimakasih..
Tidak ada komentar:
Posting Komentar