Langsung ke konten utama

Latihan menggunakan If-then-Else dan Nested-If

Latihan 1 menggunakan (IF – THEN –ELSE)


Berikut Source Codenya :

Public Class latihan1
   'nadiahtami 2017230007
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim keterangan As String
        If TextBox1.Text >= 80 Then
            keterangan = "Selamat Anda Lulus"
        Else
            keterangan = "Mohon Maaf Anda Belum Lulus"
        End If
        TextBox2.Text = keterangan
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim pesan As String
        pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            End
        End If
    End Sub
End Class

Latihan 2 menggunakan (NESTED- IF)


Berikut Source Codenya :

Public Class latihan2
    'nadiahtami 2017230007
    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox1.Text = "Garuda" Then
            If ComboBox2.Text = "Medan-Padang" Then
                TextBox1.Text = 500000
            ElseIf ComboBox2.Text = "Medan-Jakarta" Then
                TextBox1.Text = 1000000
            ElseIf ComboBox2.Text = "Medan-Bali" Then
                TextBox1.Text = 1500000
            End If
        ElseIf ComboBox1.Text = "Lion" Then
            If ComboBox2.Text = "Medan-Padang" Then
                TextBox1.Text = 300000
            ElseIf ComboBox2.Text = "Medan-Jakarta" Then
                TextBox1.Text = 600000
            ElseIf ComboBox2.Text = "Medan-Bali" Then
                TextBox1.Text = 800000
            End If
        ElseIf ComboBox1.Text = "Sriwijaya" Then
            If ComboBox2.Text = "Medan-Padang" Then
                TextBox1.Text = 400000
            ElseIf ComboBox2.Text = "Medan-Jakarta" Then
                TextBox1.Text = 800000
            ElseIf ComboBox2.Text = "Medan-Bali" Then
                TextBox1.Text = 1000000
            End If
        End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim pesan As String
        pesan = MsgBox("Yakin Ingin Keluar??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            End
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ComboBox1.Text = ""
        ComboBox2.Text = ""
        TextBox1.Text = ""
    End Sub

End Class

Komentar

Postingan populer dari blog ini

Latihan dan Kasus Array Multidimensi pada VB.NET

Latihan 1 Array Multidimensi Berikut Source Codenya : Public Class latihan4     'nadiahtami 2017230007'     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         Dim arr(4) As String         arr(0) = TextBox1.Text         arr(1) = TextBox2.Text         arr(2) = ComboBox1.Text         arr(3) = ComboBox2.Text         Dim list As New ListViewItem         list = ListView1.Items.Add(arr(0))         list.SubItems.Add(arr(1))         list.SubItems.Add(arr(2))         list.SubItems.Add(arr(3))         TextBox1.Text = TextBox1.Text + 1         TextBox2.Text = ""         ComboBox1.Text = ""         C...

Contoh Kasus Menggunakan IIF dan Select-Case pada VB.NET

Kasus 6 Menggunakan IIF Berikut Source Code nya: Public Class kasus6     'nadiahtami 2017230007     Dim hadir, tugas, uts, uas, akhir As Integer     Dim grade, keterangan As String     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click         Application.Exit()     End Sub     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         TextBox1.Text = ""         TextBox2.Text = ""         TextBox3.Text = ""         TextBox4.Text = ""         TextBox5.Text = ""         TextBox6.Text = ""         TextBox7.Text = ""         TextBox8.Text = ""         ComboBox1.Text = ""     End Sub  ...