Mengakifkan dan Menonaktifkan Control-Control pada Program dengan Perulangan + Puzle Sederhana


Program dibawah ini adalah modifikasi dari tugas sebelumnya. Saat program dijalakan, semua isian tidak aktif, tombol isi data dan tutup aktif sedangkan tombol clear tidak aktif.

Saat Program Dijalankan

Berikut ini coding dari Form1_Load :

Coding Dari Form1_Load

Saat tombol isi data ditekan, kodebarang, jumlah barang, cara beli dan tombol clear aktif, sedangkan tombol isidata tidak aktif.

Setelah Tombol “Isi Data” Ditekan

Berikut ini coding dari btisi :

Coding Dari btisi

Saat tombol clear ditekan, tampilannya sama dengan ketika program dijalankan.

Setelah Tombol Clear Ditekan

Berikut ini coding dari btclear :

Coding dari btclear

Game Puzle Sederhana
Buat sebuah form dengan 9 tombol yaitu Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, dan Button9.
Ubah semua textnya menjadi sesuai dengan urutannya, cotoh 1 untuk Button1, 2 untuk Button2 dan seterusnya.
Ubah Visible dari Button9 menjadi False.

Saat form dijalankan posisi angka acak.

Saat Form Dijalankan Posisi Angka Acak

Saat ditekan tombol yang terletak di dekat tombol kosong maka tombol tersebut akan menempati tombok kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8.

Saat Salah Satu Tombol Dekat Area Kosong Ditekan

Saat angka sudah tersusun game akan menampilkan pesan “Selamat Anda Berhasil.

Muncul Pesan “Selamat Anda Berhasil”

Listing Program :
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button4.Visible = False Then
Button1.Visible = False
Button4.Visible = True
Button4.Text = Button1.Text
ElseIf Button2.Visible = False Then
Button1.Visible = False
Button2.Visible = True
Button2.Text = Button1.Text
End If
pesan()
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button1.Visible = False Then
Button2.Visible = False
Button1.Visible = True
Button1.Text = Button2.Text
ElseIf Button5.Visible = False Then
Button2.Visible = False
Button5.Visible = True
Button5.Text = Button2.Text
ElseIf Button3.Visible = False Then
Button2.Visible = False
Button3.Visible = True
Button3.Text = Button2.Text
End If
pesan()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button6.Visible = False Then
Button3.Visible = False
Button6.Visible = True
Button6.Text = Button3.Text
ElseIf Button2.Visible = False Then
Button3.Visible = False
Button2.Visible = True
Button2.Text = Button3.Text
End If
pesan()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button1.Visible = False Then
Button4.Visible = False
Button1.Visible = True
Button1.Text = Button4.Text
ElseIf Button7.Visible = False Then
Button4.Visible = False
Button7.Visible = True
Button7.Text = Button4.Text
ElseIf Button5.Visible = False Then
Button4.Visible = False
Button5.Visible = True
Button5.Text = Button4.Text
End If
pesan()
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If Button2.Visible = False Then
Button5.Visible = False
Button2.Visible = True
Button2.Text = Button5.Text
ElseIf Button4.Visible = False Then
Button5.Visible = False
Button4.Visible = True
Button4.Text = Button5.Text
ElseIf Button6.Visible = False Then
Button5.Visible = False
Button6.Visible = True
Button6.Text = Button5.Text
ElseIf Button8.Visible = False Then
Button5.Visible = False
Button8.Visible = True
Button8.Text = Button5.Text
End If
pesan()
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button3.Visible = False Then
Button6.Visible = False
Button3.Visible = True
Button3.Text = Button6.Text
ElseIf Button9.Visible = False Then
Button6.Visible = False
Button9.Visible = True
Button9.Text = Button6.Text
ElseIf Button5.Visible = False Then
Button6.Visible = False
Button5.Visible = True
Button5.Text = Button6.Text
End If
pesan()
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Button4.Visible = False Then
Button7.Visible = False
Button4.Visible = True
Button4.Text = Button7.Text
ElseIf Button8.Visible = False Then
Button7.Visible = False
Button8.Visible = True
Button8.Text = Button7.Text
End If
pesan()
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Button9.Visible = False Then
Button8.Visible = False
Button9.Visible = True
Button9.Text = Button8.Text
ElseIf Button7.Visible = False Then
Button8.Visible = False
Button7.Visible = True
Button7.Text = Button8.Text
ElseIf Button5.Visible = False Then
Button8.Visible = False
Button5.Visible = True
Button5.Text = Button8.Text
End If
pesan()
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
If Button6.Visible = False Then
Button9.Visible = False
Button6.Visible = True
Button6.Text = Button9.Text
ElseIf Button8.Visible = False Then
Button9.Visible = False
Button8.Visible = True
Button8.Text = Button9.Text
End If
pesan()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim acak As Integer
acak = Rnd() * 10
Button1.Text = acak
Button2.Text = acak – 2
Button3.Text = acak – 5
Button4.Text = acak – 3
Button5.Text = acak + 1
Button6.Text = acak – 1
Button7.Text = acak – 6
Button8.Text = acak – 4
End Sub

Private Sub pesan()
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” Then
MsgBox(“Selamat Anda Berhasil”)
End If
End Sub
End Class