Soal 1
Program saat belum ada penambahan ataupun modivikasi :
1.Saat form dijalankan : semua isian tidak aktif, tombol
isidata dan tutup aktif, tombol clear tidak aktif
script program :
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
Control.Enabled = False
Button2.Enabled = True
Button1.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
2.Saat ditekan tombol isi data : kodebarang, jumlahbarang,
cara beli, tombol clear, aktif, tombol isidata tidak aktif
sript program :
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
Control.Enabled = True
Button1.Enabled = False
Next
End Sub
3.Saat ditekan combol clear sama dengan saat form dijalankan
script program :
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
Button2.Enabled = True
Button1.Enabled = True
Next
Txtbayar.Clear()
Txtdiskon.Clear()
Txtharga.Clear()
Txtjumlah.Clear()
Txtnama.Clear()
Txttotal.Clear()
Me.Radiotunai.Checked = False
Me.Radiokredit.Checked = False
cmbkode.Text = “”
End Sub
Maka keseluruhan script program ini :
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
Control.Enabled = False
Button2.Enabled = True
Button1.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
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 = 200000
Case Else
namabarang = “_”
harga = 0
End Select
Txtnama.Text = namabarang
Txtharga.Text = harga
Txtharga.Text = Format(harga, “#,#”)
End Sub
Private Sub Txtjumlah_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Txtjumlah.TextChanged
Dim total As Single
Txttotal.Text = Val(Txtharga.Text) * Val(Txtjumlah.Text)
Txtbayar.Text = Val(Txttotal.Text) – Val(Txtdiskon.Text)
Txttotal.Text = Format(total, “#,#”)
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
Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
Control.Enabled = False
Button2.Enabled = True
Button1.Enabled = True
Next
Txtbayar.Clear()
Txtdiskon.Clear()
Txtharga.Clear()
Txtjumlah.Clear()
Txtnama.Clear()
Txttotal.Clear()
Me.Radiotunai.Checked = False
Me.Radiokredit.Checked = False
cmbkode.Text = “”
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim Control As Windows.Forms.Control
For Each Control In Me.Controls
Control.Enabled = True
Button1.Enabled = False
Next
End Sub
End Class
Soal 2
2.Saat ditekan tombol yang terletak di dekat tombol kosong
maka tombol tersebut akan menempati tombol
kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8
kosong, begitu seterusnya sampai dengan angkanya tersusun dari 1 sampai 8
Script Program :
Public Class Form1
Dim jalan As Boolean = False
Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
If b2.Text
= "" Then
b2.Text
= b1.Text
b1.Text
= ""
End If
If b4.Text
= "" Then
b4.Text
= b1.Text
b1.Text
= ""
End If
End Sub
Private Sub b2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b2.Click
If b1.Text
= "" Then
b1.Text
= b2.Text
b2.Text
= ""
End If
If b5.Text
= "" Then
b5.Text
= b2.Text
b2.Text
= ""
End If
If b3.Text
= "" Then
b3.Text
= b2.Text
b2.Text
= ""
End If
End Sub
Private Sub b3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b3.Click
If b2.Text
= "" Then
b2.Text
= b3.Text
b3.Text
= ""
End If
If b6.Text
= "" Then
b6.Text
= b3.Text
b3.Text
= ""
End If
End Sub
Private Sub b4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b4.Click
If b1.Text
= "" Then
b1.Text
= b4.Text
b4.Text
= ""
End If
If b5.Text
= "" Then
b5.Text
= b4.Text
b4.Text
= ""
End If
If b7.Text
= "" Then
b7.Text
= b4.Text
b4.Text
= ""
End If
End Sub
Private Sub b5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b5.Click
If b2.Text
= "" Then
b2.Text
= b5.Text
b5.Text
= ""
End If
If b4.Text
= "" Then
b4.Text
= b5.Text
b5.Text
= ""
End If
If b6.Text
= "" Then
b6.Text
= b5.Text
b5.Text
= ""
End If
If b8.Text
= "" Then
b8.Text
= b5.Text
b5.Text
= ""
End If
End Sub
Private Sub b6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b6.Click
If b3.Text
= "" Then
b3.Text
= b6.Text
b6.Text
= ""
End If
If b5.Text
= "" Then
b5.Text
= b6.Text
b6.Text
= ""
End If
If b9.Text
= "" Then
b9.Text
= b6.Text
b6.Text
= ""
End If
End Sub
Private Sub b7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b7.Click
If b4.Text
= "" Then
b4.Text
= b7.Text
b7.Text
= ""
End If
If b8.Text
= "" Then
b8.Text
= b7.Text
b7.Text
= ""
End If
End Sub
Private Sub b8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b8.Click
If b5.Text
= "" Then
b5.Text
= b8.Text
b8.Text
= ""
End If
If b9.Text
= "" Then
b9.Text
= b8.Text
b8.Text
= ""
End If
If b7.Text
= "" Then
b7.Text
= b8.Text
b8.Text
= ""
End If
If (b1.Text
= "1" And b2.Text
= "2" And b3.Text
= "3" And b4.Text
= "4" And b5.Text
= "5" And b6.Text ="6" And b7.Text
= 7 And b8.Text = "8" And b9.Text
= "") Then
MsgBox("selamat
anda berhasil")
End If
End Sub
Private Sub b9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b9.Click
If b8.Text
= "" Then
b8.Text
= b9.Text
b9.Text
= ""
End If
If b6.Text
= "" Then
b6.Text
= b9.Text
b9.Text
= ""
End If
If (b1.Text
= "1" And b2.Text
= "2" And b3.Text
= "3" And b4.Text
= "4" And b5.Text = "5" And b6.Text
="6" And b7.Text = "7" And b8.Text
= "8" And b9.Text = "") Then
MsgBox("selamat
anda berhasil")
End If
End Sub
Private Sub bacak_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bacak.Click
jalan
= Not jalan
Timer1.Enabled
= jalan
If Timer1.Enabled
= True Then
bacak.Text
= "STOP"
Else
bacak.Text
= "ACAK"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim acak As Integer
Do
acak
= Rnd() * 10
b1.Text
= acak
' If
b1.Text = 10 Or b1.Text = 0 Or b1.Text = 9 Then
'b1.Text
= ""
'End
If
Loop While acak
= 10 Or acak = 9
Do
acak
= Rnd() * 10
b2.Text
= acak
'If
b2.Text = 10 Or b2.Text = 0 Or b2.Text = 9 Then
'b2.Text
= ""
'
End If
Loop While b2.Text
= b1.Text Or acak = 10 Or acak = 9
Do
acak
= Rnd() * 10
b3.Text
= acak
' If
b3.Text = 10 Or b3.Text = 0 Or b3.Text = 9 Then
'b3.Text
= ""
'End
If
Loop While acak
= b1.Text Or acak = b2.Text Or acak = 10 Or acak
= 9
Do
acak
= Rnd() * 10
b4.Text
= acak
'
If b4.Text = 10 Or b4.Text = 0 Or b4.Text = 9 Then
'b4.Text
= ""
'
End If
Loop While acak
= b1.Text Or acak = b2.Text Or acak =
b3.Text Or acak = 10 Or acak = 9
Do
acak
= Rnd() * 10
b5.Text
= acak
'If
b5.Text = 10 Or b5.Text = 0 Or b5.Text = 9 Then
'b5.Text
= ""
'End
If
Loop While acak
= b1.Text Or acak = b2.Text Or acak =
b3.Text Or acak = b4.Text Or acak = 10 Or acak =
9
Do
acak
= Rnd() * 10
b6.Text
= acak
'If
b6.Text = 10 Or b6.Text = 0 Or b6.Text = 9 Then
'b6.Text
= ""
'End
If
Loop While acak
= b1.Text Or acak = b2.Text Or acak =
b3.Text Or acak = b4.Text Or acak = b5.Text Or acak
= 10 Or acak = 9
Do
acak
= Rnd() * 10
b7.Text
= acak
'If
b7.Text = 10 Or b7.Text = 0 Or b7.Text = 9 Then
'b7.Text
= ""
'End
If
Loop While acak
= b1.Text Or acak = b2.Text Or acak =
b3.Text Or acak = b4.Text Or acak =
b5.Text Or acak = b6.Text Or acak = 10 Or acak =
9
Do
acak
= Rnd() * 10
b8.Text
= acak
' If
b8.Text = 10 Or b8.Text = 0 Or b8.Text = 9 Then
'b8.Text
= ""
'End
If
Loop While acak
= b1.Text Or acak = b2.Text Or acak =
b3.Text Or acak = b4.Text Or acak =
b5.Text Or acak = b6.Text Or acak = b7.Text Or acak
= 10 Or acak = 9
Do
acak
= Rnd() * 10
b9.Text
= acak
'
If b9.Text = 10 Or b9.Text = 0 Or b9.Text = 9 Then
'b9.Text
= ""
'End
If
Loop While acak
= b1.Text Or acak = b2.Text Or acak =
b3.Text Or acak = b4.Text Or acak =
b5.Text Or acak = b6.Text Or acak =
b7.Text Or acak = b8.Text Or acak = 10 Or acak =
9
Dim control As Windows.Forms.Control
For Each control In Me.Controls
If control.Text
= "0" Then
control.Text
= ""
End If
Next
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
Semoga Tugas VB ke-3 ini bermanfaat :)
Semoga Tugas VB ke-3 ini bermanfaat :)