Tugas 3
1. Memodifikasi Program If dan case praktikum ke-2 dengan:
a. menon aktifkan tombol Clear dan semua isian data kecuali tombol Isi data dan tombol Tutup.
b. mengaktifkan tombol clear dan isisan kodebarang, jumlahbarang, cara beli.
c. mengembalikan keadaan seperti saat program dijalankan ketika menekan tombol Clear.
Kemudian listing program :
Public Class Form1
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")
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-Sirt"
harga = 1500000
Case "TOP"
namaBarang = "Topi"
harga = 500000
Case "TAS"
namaBarang = "Tas"
harga = 700000
Case Else
namaBarang = "-"
harga = 0
End Select
txtNama.Text = namaBarang
txtHarga.Text = harga
txtTotal.Text = Val(txtHarga.Text) * Val(txtJumlah.Text)
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
If radioTunai.Checked = True Then
txtDiskon.Text = Val(txtTotal.Text) * 10 / 100
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
ElseIf radioKredit.Checked = True Then
txtDiskon.Text = 0
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
End If
End Sub
Private Sub txtJumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJumlah.TextChanged
txtTotal.Text = Val(txtHarga.Text) * Val(txtJumlah.Text)
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
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
txtDiskon.Clear()
txtHarga.Clear()
txtJumlah.Clear()
txtTotal.Clear()
txtNama.Clear()
cmbKode.Text = ""
Me.radioTunai.Checked = False
Me.radioKredit.Checked = False
cmbKode.Enabled = False
radioKredit.Enabled = False
radioTunai.Enabled = False
txtJumlah.Enabled = False
btClear.Enabled = False
End Sub
Private Sub btTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btTutup.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cmbKode.Enabled = True
txtJumlah.Enabled = True
radioKredit.Enabled = True
radioTunai.Enabled = True
btClear.Enabled = True
End Sub
End Class
Setelah dijalankan dan berhasil diurutkan:
Listing Program:
Public Class Form1
Dim tampung As String
Private Sub bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt1.Click
tampung = bt1.Text
If bt2.Text = "" Then
bt1.Text = ""
bt2.Text = tampung
ElseIf bt4.Text = "" Then
bt1.Text = ""
bt4.Text = tampung
ElseIf bt5.Text = "" Then
bt1.Text = ""
bt5.Text = tampung
End If
End Sub
Private Sub bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt2.Click
tampung = bt2.Text
If bt1.Text = "" Then
bt2.Text = ""
bt1.Text = tampung
ElseIf bt3.Text = "" Then
bt2.Text = ""
bt3.Text = tampung
End If
End Sub
Private Sub bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt3.Click
tampung = bt3.Text
If bt2.Text = "" Then
bt3.Text = ""
bt2.Text = tampung
ElseIf bt5.Text = "" Then
bt3.Text = ""
bt5.Text = tampung
ElseIf bt6.Text = "" Then
bt3.Text = ""
bt6.Text = tampung
End If
End Sub
Private Sub bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt4.Click
tampung = bt4.Text
If bt9.Text = "" Then
bt4.Text = ""
bt9.Text = tampung
ElseIf bt1.Text = "" Then
bt4.Text = ""
bt1.Text = tampung
End If
End Sub
Private Sub bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt5.Click
tampung = bt5.Text
If bt1.Text = "" Then
bt5.Text = ""
bt1.Text = tampung
ElseIf bt3.Text = "" Then
bt5.Text = ""
bt3.Text = tampung
ElseIf bt8.Text = "" Then
bt5.Text = ""
bt8.Text = tampung
ElseIf bt9.Text = "" Then
bt5.Text = ""
bt9.Text = tampung
End If
End Sub
Private Sub bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt6.Click
tampung = bt6.Text
If bt3.Text = "" Then
bt6.Text = ""
bt3.Text = tampung
ElseIf bt8.Text = "" Then
bt6.Text = ""
bt8.Text = tampung
End If
If bt4.Text = "1" And bt1.Text = "2" And
bt2.Text = "3" And
bt9.Text = "4" And
bt5.Text = "5" And
bt3.Text = "6" And
bt7.Text = "7" And
bt8.Text = "8" Then
MsgBox("Anda Menang!!!")
End If
End Sub
Private Sub bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt7.Click
tampung = bt7.Text
If bt9.Text = "" Then
bt7.Text = ""
bt9.Text = tampung
ElseIf bt8.Text = "" Then
bt7.Text = ""
bt8.Text = tampung
End If
End Sub
Private Sub bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt8.Click
tampung = bt8.Text
If bt5.Text = "" Then
bt8.Text = ""
bt5.Text = tampung
ElseIf bt6.Text = "" Then
bt8.Text = ""
bt6.Text = tampung
ElseIf bt7.Text = "" Then
bt8.Text = ""
bt7.Text = tampung
End If
End Sub
Private Sub bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt9.Click
tampung = bt9.Text
If bt4.Text = "" Then
bt9.Text = ""
bt4.Text = tampung
ElseIf bt5.Text = "" Then
bt9.Text = ""
bt5.Text = tampung
ElseIf bt7.Text = "" Then
bt9.Text = ""
bt7.Text = tampung
End If
End Sub
End Class
1. Memodifikasi Program If dan case praktikum ke-2 dengan:
a. menon aktifkan tombol Clear dan semua isian data kecuali tombol Isi data dan tombol Tutup.
b. mengaktifkan tombol clear dan isisan kodebarang, jumlahbarang, cara beli.
c. mengembalikan keadaan seperti saat program dijalankan ketika menekan tombol Clear.
Kemudian listing program :
Public Class Form1
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")
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-Sirt"
harga = 1500000
Case "TOP"
namaBarang = "Topi"
harga = 500000
Case "TAS"
namaBarang = "Tas"
harga = 700000
Case Else
namaBarang = "-"
harga = 0
End Select
txtNama.Text = namaBarang
txtHarga.Text = harga
txtTotal.Text = Val(txtHarga.Text) * Val(txtJumlah.Text)
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
If radioTunai.Checked = True Then
txtDiskon.Text = Val(txtTotal.Text) * 10 / 100
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
ElseIf radioKredit.Checked = True Then
txtDiskon.Text = 0
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
End If
End Sub
Private Sub txtJumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJumlah.TextChanged
txtTotal.Text = Val(txtHarga.Text) * Val(txtJumlah.Text)
txtBayar.Text = Val(txtTotal.Text) - Val(txtDiskon.Text)
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
txtDiskon.Clear()
txtHarga.Clear()
txtJumlah.Clear()
txtTotal.Clear()
txtNama.Clear()
cmbKode.Text = ""
Me.radioTunai.Checked = False
Me.radioKredit.Checked = False
cmbKode.Enabled = False
radioKredit.Enabled = False
radioTunai.Enabled = False
txtJumlah.Enabled = False
btClear.Enabled = False
End Sub
Private Sub btTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btTutup.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
cmbKode.Enabled = True
txtJumlah.Enabled = True
radioKredit.Enabled = True
radioTunai.Enabled = True
btClear.Enabled = True
End Sub
End Class
2. Permainan Punzle sederhana:
Buat form :
Setelah dijalankan dan berhasil diurutkan:
Listing Program:
Public Class Form1
Dim tampung As String
Private Sub bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt1.Click
tampung = bt1.Text
If bt2.Text = "" Then
bt1.Text = ""
bt2.Text = tampung
ElseIf bt4.Text = "" Then
bt1.Text = ""
bt4.Text = tampung
ElseIf bt5.Text = "" Then
bt1.Text = ""
bt5.Text = tampung
End If
End Sub
Private Sub bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt2.Click
tampung = bt2.Text
If bt1.Text = "" Then
bt2.Text = ""
bt1.Text = tampung
ElseIf bt3.Text = "" Then
bt2.Text = ""
bt3.Text = tampung
End If
End Sub
Private Sub bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt3.Click
tampung = bt3.Text
If bt2.Text = "" Then
bt3.Text = ""
bt2.Text = tampung
ElseIf bt5.Text = "" Then
bt3.Text = ""
bt5.Text = tampung
ElseIf bt6.Text = "" Then
bt3.Text = ""
bt6.Text = tampung
End If
End Sub
Private Sub bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt4.Click
tampung = bt4.Text
If bt9.Text = "" Then
bt4.Text = ""
bt9.Text = tampung
ElseIf bt1.Text = "" Then
bt4.Text = ""
bt1.Text = tampung
End If
End Sub
Private Sub bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt5.Click
tampung = bt5.Text
If bt1.Text = "" Then
bt5.Text = ""
bt1.Text = tampung
ElseIf bt3.Text = "" Then
bt5.Text = ""
bt3.Text = tampung
ElseIf bt8.Text = "" Then
bt5.Text = ""
bt8.Text = tampung
ElseIf bt9.Text = "" Then
bt5.Text = ""
bt9.Text = tampung
End If
End Sub
Private Sub bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt6.Click
tampung = bt6.Text
If bt3.Text = "" Then
bt6.Text = ""
bt3.Text = tampung
ElseIf bt8.Text = "" Then
bt6.Text = ""
bt8.Text = tampung
End If
If bt4.Text = "1" And bt1.Text = "2" And
bt2.Text = "3" And
bt9.Text = "4" And
bt5.Text = "5" And
bt3.Text = "6" And
bt7.Text = "7" And
bt8.Text = "8" Then
MsgBox("Anda Menang!!!")
End If
End Sub
Private Sub bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt7.Click
tampung = bt7.Text
If bt9.Text = "" Then
bt7.Text = ""
bt9.Text = tampung
ElseIf bt8.Text = "" Then
bt7.Text = ""
bt8.Text = tampung
End If
End Sub
Private Sub bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt8.Click
tampung = bt8.Text
If bt5.Text = "" Then
bt8.Text = ""
bt5.Text = tampung
ElseIf bt6.Text = "" Then
bt8.Text = ""
bt6.Text = tampung
ElseIf bt7.Text = "" Then
bt8.Text = ""
bt7.Text = tampung
End If
End Sub
Private Sub bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt9.Click
tampung = bt9.Text
If bt4.Text = "" Then
bt9.Text = ""
bt4.Text = tampung
ElseIf bt5.Text = "" Then
bt9.Text = ""
bt5.Text = tampung
ElseIf bt7.Text = "" Then
bt9.Text = ""
bt7.Text = tampung
End If
End Sub
End Class