Kamis, Oktober 15, 2015

Penggunaan Case Pada Visual Studio 2008

Contoh Penggunaan Case Pada Visual Studio 2008


Setting Properties :

 
 
Source code :




Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call isimaskapai()
        Call isitujuan()
        Call bersih()
    End Sub
    Sub isimaskapai()
        Maskapai.Items.Add("Garuda")
        Maskapai.Items.Add("Lion")
        Maskapai.Items.Add("Sriwijaya")
    End Sub
    Sub isitujuan()
        Tujuan.Items.Add("Medan-Padang")
        Tujuan.Items.Add("Medan-Jakarta")
        Tujuan.Items.Add("Medan-Bali")
    End Sub
    Sub bersih()
        Maskapai.Text = ""
        Tujuan.Text = ""
        Harga.Text = ""
        Nama.Text = ""
        Jumlah.Text = ""
        Total.Text = ""
    End Sub
    Private Sub Batal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Batal.Click
        Call bersih()
    End Sub
    Private Sub Keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Keluar.Click
        Me.Close()
    End Sub
    Private Sub Hitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Hitung.Click
        Total.Text = Harga.Text * Jumlah.Text
    End Sub
    Private Sub Tujuan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tujuan.SelectedIndexChanged
        Select Case (Maskapai.Text)
            Case "Garuda"
                Select Case (Tujuan.Text)
                    Case "Medan-Padang"
                        Harga.Text = 570000
                    Case "Medan-Jakarta"
                        Harga.Text = 800000
                    Case "Medan-Bali"
                        Harga.Text = 980000
                End Select
            Case "Lion"
                Select Case (Tujuan.Text)
                    Case "Medan-Padang"
                        Harga.Text = 390000
                    Case "Medan-Jakarta"
                        Harga.Text = 630000
                    Case "Medan-Bali"
                        Harga.Text = 780000
                End Select
            Case "Sriwijaya"
                Select Case (Tujuan.Text)
                    Case "Medan-Padang"
                        Harga.Text = 420000
                    Case "Medan-Jakarta"
                        Harga.Text = 700000
                    Case "Medan-Bali"
                        Harga.Text = 870000
                End Select
        End Select
    End Sub
    Private Sub Maskapai_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Maskapai.SelectedIndexChanged
        Tujuan_SelectedIndexChanged(sender, e)
    End Sub
    Private Sub Jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Jumlah.KeyPress
        If Asc(e.KeyChar) = 13 Then
            Hitung_Click(sender, e)
        End If
    End Sub
    Private Sub Jumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Jumlah.TextChanged
    End Sub
End Class