Pemrograman Visual:Latihan Ujian: Difference between revisions
No edit summary |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[File:Pemrograman visula latihan ujian 1029384.PNG|thumb]] | |||
Kode ini memerlukan sebuah objek <code>ComboBox</code> yang disebut <code>cboJenis</code> yang digunakan untuk memilih jenis mobil, sebuah objek TextBox yang disebut <code>txtJumlahHari</code> yang digunakan untuk memasukkan jumlah hari sewa, sebuah objek <code>TextBox</code> yang disebut <code>txtSewaPerHari</code> yang digunakan untuk menampilkan harga sewa per hari, dan sebuah objek <code>TextBox</code> yang disebut <code>txtJumlahBayar</code> yang digunakan untuk menampilkan jumlah bayar. | Kode ini memerlukan sebuah objek <code>ComboBox</code> yang disebut <code>cboJenis</code> yang digunakan untuk memilih jenis mobil, sebuah objek TextBox yang disebut <code>txtJumlahHari</code> yang digunakan untuk memasukkan jumlah hari sewa, sebuah objek <code>TextBox</code> yang disebut <code>txtSewaPerHari</code> yang digunakan untuk menampilkan harga sewa per hari, dan sebuah objek <code>TextBox</code> yang disebut <code>txtJumlahBayar</code> yang digunakan untuk menampilkan jumlah bayar. | ||
| Line 30: | Line 31: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Kode dibawah memiliki 2 event, pada saat index pada comboBox berubah, dan satu lagi pada saat text pada TextBox JumlahHari berubah, sehingga otomatis akan menghitung dengan sendirinya | Kode dibawah memiliki 2 event, pada saat index pada <code>comboBox</code> berubah, dan satu lagi pada saat text pada <code>TextBox JumlahHari</code> berubah, sehingga otomatis akan menghitung dengan sendirinya | ||
<syntaxhighlight lang="vbnet" line="1"> | <syntaxhighlight lang="vbnet" line="1"> | ||
| Line 66: | Line 67: | ||
harga = Val(txtSewaPerHari.Text) | harga = Val(txtSewaPerHari.Text) | ||
txtJumlahBayar.Text = harga * Val(txtJumlahHari.Text) | txtJumlahBayar.Text = harga * Val(txtJumlahHari.Text) | ||
End Sub | |||
End Class | |||
</syntaxhighlight>Dibawah ini adalah kode untuk menambahkan pilihan pada <code>comboBox</code><syntaxhighlight lang="vbnet" line="1"> | |||
Public Class Form1 | |||
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load | |||
cboJenis.Items.Add("Bus") | |||
cboJenis.Items.Add("Sedan") | |||
cboJenis.Items.Add("Kijang") | |||
cboJenis.Items.Add("Carry") | |||
End Sub | |||
Private Sub cboJenis_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboJenis.SelectedIndexChanged | |||
Dim jenis As String | |||
Dim harga As Integer | |||
jenis = cboJenis.Text | |||
Select Case jenis | |||
Case "Bus" | |||
harga = 1000000 | |||
Case "Sedan" | |||
harga = 800000 | |||
Case "Kijang" | |||
harga = 400000 | |||
Case "Carry" | |||
harga = 200000 | |||
Case Else | |||
harga = 0 | |||
MsgBox("Jenis mobil tidak ditemukan!") | |||
End Select | |||
If harga <> 0 Then | |||
txtSewaPerHari.Text = harga | |||
txtJumlahBayar.Text = harga * Val(txtJumlahHari.Text) | |||
Else | |||
txtSewaPerHari.Text = "" | |||
txtJumlahBayar.Text = "" | |||
End If | |||
End Sub | |||
Private Sub txtJumlahHari_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtJumlahHari.TextChanged | |||
Dim harga As Integer | |||
harga = Val(txtSewaPerHari.Text) | |||
txtJumlahBayar.Text = harga * Val(txtJumlahHari.Text) | |||
End Sub | |||
End Class | |||
</syntaxhighlight>Kode dibawah ini di event <code>btnBersihkan_Click</code> digunakan untuk mengosongkan semua input pada form, sedangkan pada event <code>btnKeluar_Click</code> digunakan untuk menutup form. | |||
<syntaxhighlight lang="vbscript" line="1"> | |||
Public Class Form1 | |||
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load | |||
cboJenis.Items.Add("Bus") | |||
cboJenis.Items.Add("Sedan") | |||
cboJenis.Items.Add("Kijang") | |||
cboJenis.Items.Add("Carry") | |||
End Sub | |||
Private Sub cboJenis_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboJenis.SelectedIndexChanged | |||
Dim jenis As String | |||
Dim harga As Integer | |||
jenis = cboJenis.Text | |||
Select Case jenis | |||
Case "Bus" | |||
harga = 1000000 | |||
Case "Sedan" | |||
harga = 800000 | |||
Case "Kijang" | |||
harga = 400000 | |||
Case "Carry" | |||
harga = 200000 | |||
Case Else | |||
harga = 0 | |||
MsgBox("Jenis mobil tidak ditemukan!") | |||
End Select | |||
If harga <> 0 Then | |||
txtSewaPerHari.Text = harga | |||
txtJumlahBayar.Text = harga * Val(txtJumlahHari.Text) | |||
Else | |||
txtSewaPerHari.Text = "" | |||
txtJumlahBayar.Text = "" | |||
End If | |||
End Sub | |||
Private Sub txtJumlahHari_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtJumlahHari.TextChanged | |||
Dim harga As Integer | |||
harga = Val(txtSewaPerHari.Text) | |||
txtJumlahBayar.Text = harga * Val(txtJumlahHari.Text) | |||
End Sub | |||
Private Sub btnBersihkan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBersihkan.Click | |||
cboJenis.Text = "" | |||
txtJumlahHari.Text = "" | |||
txtSewaPerHari.Text = "" | |||
txtJumlahBayar.Text = "" | |||
txtNamaPenyewa.Text = "" | |||
txtNomorSewa.Text = "" | |||
End Sub | |||
Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click | |||
Me.Close() | |||
End Sub | End Sub | ||
End Class | End Class | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Materi]] | [[Category:Materi]] | ||
[[Category:Matkul]] | [[Category:Matkul]] | ||
[[Category:Pemrograman]] | [[Category:Pemrograman]] | ||
[[Category:Pemrograman Visual]] | [[Category:Pemrograman Visual]] | ||