Pemrograman Visual:Latihan Ujian: Difference between revisions

No edit summary
No edit summary
Line 112: Line 112:
         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>
<syntaxhighlight lang="bash">
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
   
    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 = ""
    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