MODIFIKASI PROGRAM DAN MEMBUAT PROGRAM PUZZLE .
Pada blog saya kali ini, saya akan memaparkan hasil tugas yang diberikan pada pertemuan ke-4 minggu lalu , tentang memodifikasi program yang sudah dibuat pada pertemuan ke- 3 yaitu Latihan IF dan Case menggunakan perulangan .
Selain memodifikasi program ,dalam tugas 3 kali ini juga diberikan tugas untuk membuat puzzle menggunakan visual basic 2010.
Bagaimana ulasannya , mari kita pelajari dibawah ini :
1 ) MODIFIKASI LATIHAN IF DAN CASE .
Pada program modifikasi menggunakan perulangan ini saya menggunakan perintah FOR EACH.
For Each digunakan untuk melakukan iterasi berdasarkan collection tertentu.
* Syntax Program Menggunakan Perulangan .
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbkode.Items.Add("SPT")
cmbkode.Items.Add("SND")
cmbkode.Items.Add("TST")
cmbkode.Items.Add("TOP")
cmbkode.Items.Add("TAS")
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 = "ComboBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = False
End If
Next
Btclear.Enabled = False
End Sub
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"
harga = 250000
Case Else
namabarang = "-"
harga = 0
End Select
txtnama.Text = namabarang
txtharga.Text = harga
Me.radiotunai.Checked = False
Me.radiokredit.Checked = False
txtbayar.Clear()
txtdiskon.Clear()
txtjumlah.Clear()
txttotal.Clear()
txtjumlah.Focus()
End Sub
Private Sub txtjumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtjumlah.TextChanged
If (txtjumlah.Text = "") Then
Else
Dim jumlah As Integer
Try
jumlah = Convert.ToInt32(txtjumlah.Text)
Catch ex As Exception
jumlah = 0
MsgBox("Jumlah barang harus berupa angka", MsgBoxStyle.Critical, "Peringatan")
End Try
txttotal.Text = Val(txtharga.Text) * jumlah
txtbayar.Text = Val(txttotal.Text) - Val(txtdiskon.Text)
End If
End Sub
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
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
Private Sub Btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclear.Click
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
Me.radiotunai.Checked = False
Me.radiokredit.Checked = False
txtbayar.Clear()
txtdiskon.Clear()
txtharga.Clear()
txtjumlah.Clear()
txtnama.Clear()
txttotal.Clear()
cmbkode.Text = ""
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 = "ComboBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = False
End If
Next
Btclear.Enabled = False
Btisidata.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Hand)
If (MsgBox("Apa Anda yakin untuk menutup aplikasi ini?", vbQuestion + vbYesNo + vbDefaultButton2, "Konfirmasi")) = vbYes Then
Me.Close()
End If
End Sub
Private Sub Btisidata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btisidata.Click
Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
If Control.GetType.Name = "ComboBox" Then
Control.Enabled = True
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = True
End If
Next
txtjumlah.Enabled = True
Btclear.Enabled = True
Btisidata.Enabled = False
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
End Class
* Ketentuan Modifikasi Program .
1 . Saat form dijalankan : semua isian tidak aktif , tombol isidata dan tutup aktif tombol clear tidak aktif.
Jawab : Dim Control As Windows.Forms.Control ' Digunakan untuk mengendalikan perintah.
For Each Control In Me.Controls ' Sistem perulangan.
If Control.GetType.Name = "ComboBox" Then '
Control.Enabled = False ' Perintah mematikan (False) .
End If
If Control.GetType.Name = "TextBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "ComboBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = False
End If
Next
Btclear.Enabled = False
End Sub
* Tampilan Program.
Jawab : Dim Control As Windows.Forms.Control ' Digunakan untuk mengendalikan perintah.
For Each Control In Me.Controls ' Sistem perulangan.
If Control.GetType.Name = "ComboBox" Then '
Control.Enabled = False ' Perintah mematikan (False) .
End If
If Control.GetType.Name = "TextBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "ComboBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = False
End If
Next
Btclear.Enabled = False
End Sub
* Tampilan Program.
2 . Saat ditekan tombol isi data : kode barang, jumlah barang, cara beli , tombol clear, aktif , tombol isi data tidak aktif .
Jawab : Private Sub Btisidata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btisidata.Click
Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
If Control.GetType.Name = "ComboBox" Then
Control.Enabled = True "Perintah mengaktifkan (True).
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = True
End If
Next
txtjumlah.Enabled = True ' Perintah aktif
Btclear.Enabled = True ' Perintah aktif
Btisidata.Enabled = False' Perintah mematikan (False) .
End Sub
* Tampilan Program .
Saat ditekan isi data tidak aktif
Jawab : Private Sub Btisidata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btisidata.Click
Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
If Control.GetType.Name = "ComboBox" Then
Control.Enabled = True "Perintah mengaktifkan (True).
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = True
End If
Next
txtjumlah.Enabled = True ' Perintah aktif
Btclear.Enabled = True ' Perintah aktif
Btisidata.Enabled = False' Perintah mematikan (False) .
End Sub
* Tampilan Program .
Saat ditekan isi data tidak aktif
3 . Saat ditekan tombol clear sama dengan tombol dijalankan .
Jawab : Private Sub Btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclear.Click
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
Me.radiotunai.Checked = False
Me.radiokredit.Checked = False
txtbayar.Clear()
txtdiskon.Clear()
txtharga.Clear()
txtjumlah.Clear()
txtnama.Clear()
txttotal.Clear()
cmbkode.Text = ""
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 = "ComboBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = False
End If
Next
Btclear.Enabled = False 'Perintah Mematikan
Btisidata.Enabled = True 'Perintah Mengaktifkan
End Sub
End Class
Jawab : Private Sub Btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btclear.Click
My.Computer.Audio.PlaySystemSound(Media.SystemSounds.Asterisk)
Me.radiotunai.Checked = False
Me.radiokredit.Checked = False
txtbayar.Clear()
txtdiskon.Clear()
txtharga.Clear()
txtjumlah.Clear()
txtnama.Clear()
txttotal.Clear()
cmbkode.Text = ""
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 = "ComboBox" Then
Control.Enabled = False
End If
If Control.GetType.Name = "RadioButton" Then
Control.Enabled = False
End If
Next
Btclear.Enabled = False 'Perintah Mematikan
Btisidata.Enabled = True 'Perintah Mengaktifkan
End Sub
End Class
Tidak ada komentar:
Posting Komentar