Senin, 13 April 2020

Visual Basic Lanjutan (Teori 2) Percabangan (Struktur If-Then, If-Then-Else dan Nested IF)

Assalamualaikum Wr, Wb Masih dengan Saya Sulthan Alawy Shihab Apakabar semuanya, salam sejahtera bagi kita semua, semoga kita selalu dilindungi Tuhan Yang Maha Esa.
Oke ini adalah tugas teori saya pada pertemuan kedua, simak ya :)


PERCABANGAN
Percabangan atau penyeleksian kondisi (Conditional Statement) merupakan suatu pernyataan yang menganalisa suatu keadaan dan mengambil keputusan berdasarkan pada hasil analisa itu.
• Hasil dari penyeleksian adalah, jika bernilai benar maka akan dikerjakan instruksi tertentu.
• Sedang jika kondisi salah, maka akan dikerjakan instruksi yang lain.

PERCABANGAN (If – Then)
• Struktur If – Then disebut juga dengan Branch Structure merupakan struktur percabangan dimana suatu ekspresi akan dikerjakan bila kondisinya terpenuhi.
• Tetapi jika kondisinya tidak terpenuhi maka ekspresi di dalam struktur if tidak akan dijalankan dan blok If akan dilompati serta program akan melakukan tindakan berikutnya.v>

Percabangan (If – Then – Else)
• Struktur If – Then – Else disebut juga dengan Selection Structure merupakan struktur percabangan di mana suatu ekspresi akan dikerjakan bila kondisinya terpenuhi.
• Tetapi jika kondisinya tidak terpenuhi maka ekspresi yang lainnya yang dikerjakan.v> Percabangan (Nested If)
• Pada kondisi tertentu di dalam struktur If –Then Else bisa ditempatkan struktur If–Then atau If–Then–Else yang lain.
• Bentuk ini disebut dengan If Tersarang atau
Nested If.


Latihan 1


Code:

Public Class Form1

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ket As String
        If TextBox1.Text >= 60 Then
            ket = "Lulus"
        Else
            ket = "Tidak Lulus"
        End If
        TextBox2.Text = ket
    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 Mau Keluar ??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Latihan 2


Code:

Public Class Form2

 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 Mau Keluar ??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            Close()
            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

Kasus 1


Code:

Public Class Form4
    Dim harga, jumlah, subtotal, diskon, total, bayar, kembali As Integer

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.TextBox2.Focus() 'Sulthan Alawy Shihab
        End If
    End Sub

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        If e.KeyChar = Chr(13) Then
            Me.ComboBox1.Focus()
        End If
        e.Handled = CBool(keyascii) 'Sulthan Alawy Shihab
    End Sub

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.TextBox3.Focus() 'Sulthan Alawy Shihab
        End If
    End Sub

Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            Me.TextBox4.Focus() 'Sulthan Alawy Shihab
        End If
    End Sub

Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            harga = Val(TextBox3.Text)
            jumlah = Val(TextBox4.Text)
            subtotal = harga * jumlah
            TextBox5.Text = subtotal
            If subtotal >= 100000 Then
                TextBox6.Text = subtotal * 5 / 100
            ElseIf subtotal <= 100 Then
                TextBox6.Text = subtotal * 0 / 100
            End If
            Me.TextBox6.Focus() 'Sulthan Alawy Shihab
        End If
    End Sub

Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            subtotal = Val(TextBox5.Text)
            diskon = Val(TextBox6.Text)
            total = subtotal - diskon
            TextBox7.Text = total
        End If
        Me.TextBox8.Focus() 'Sulthan Alawy Shihab
    End Sub

Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox8.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            total = Val(TextBox7.Text)
            bayar = Val(TextBox8.Text)
            kembali = bayar - total
            TextBox9.Text = kembali 'Sulthan Alawy Shihab
        End If
    End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
    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 Mau Keluar ??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Kasus 2


Code:

Public Class Form5
    Dim hadir, tugas, uts, uas As Integer
    Dim akhir As Double

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            Me.TextBox2.Focus() 'SULTHAN
        End If
    End Sub

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        If e.KeyChar = Chr(13) Then
            Me.ComboBox1.Focus()
        End If
        e.Handled = CBool(keyascii) 'SULTHAN
    End Sub

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        If (e.KeyChar = Chr(13)) Then
            Me.TextBox3.Focus() 'SULTHAN
        End If
    End Sub

Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            Me.TextBox4.Focus() 'SULTHAN
        End If
    End Sub

Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            Me.TextBox5.Focus() 'SULTHAN
        End If
    End Sub

Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            Me.TextBox6.Focus() 'SULTHAN
        End If
    End Sub

Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
        hadir = Val(TextBox3.Text)
        tugas = Val(TextBox4.Text)
        uts = Val(TextBox5.Text)
        uas = Val(TextBox6.Text)
        akhir = (hadir * 20 / 100) + (tugas * 25 / 100) + (uts * 25 / 100) + (uas * 30 / 100)
        TextBox7.Text = akhir
        If akhir >= 84 Then
            TextBox8.Text = "A"
            TextBox9.Text = "Memuaskan"
        ElseIf akhir >= 64 Then
            TextBox8.Text = "B"
            TextBox9.Text = "Baik"
        ElseIf akhir >= 50 Then
            TextBox8.Text = "C"
            TextBox9.Text = "Cukup"
        ElseIf akhir < 50 Then
            TextBox8.Text = "D"
            TextBox9.Text = "Gagal"
        End If
    End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
    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 Mau Keluar ??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Kasus 3


Code:

Public Class Form6
    Dim harga, jumbel, subtotal, diskon, total As Integer
    Dim bayar, kembali As Double

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.TextBox2.Focus() 'Sulthan
        End If
    End Sub

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        If e.KeyChar = Chr(13) Then
            Me.ComboBox1.Focus()
        End If
        e.Handled = CBool(keyascii) 'Sulthan
    End Sub

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        If e.KeyChar = Chr(13) Then
            Me.TextBox4.Focus()
        End If
        e.Handled = CBool(keyascii) 'Sulthan
        If ComboBox1.Text = "Dus" Then
            TextBox3.Text = 100000
        ElseIf ComboBox1.Text = "Box" Then
            TextBox3.Text = 30000
        ElseIf ComboBox1.Text = "Botol" Then
            TextBox3.Text = 15000
        ElseIf ComboBox1.Text = "Kaplet" Then
            TextBox3.Text = 5000
            If e.KeyChar = Chr(13) Then
            End If
        End If
    End Sub

Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            harga = Val(TextBox3.Text)
            jumbel = (TextBox4.Text)
            subtotal = harga * jumbel
            TextBox5.Text = subtotal
            Me.TextBox8.Focus() 'Sulthan
            If (e.KeyChar = Chr(13)) Then
                TextBox6.Text = diskon
                If jumbel >= 100 Then
                    TextBox6.Text = subtotal * 10 / 100
                ElseIf jumbel >= 50 Then
                    TextBox6.Text = subtotal * 7 / 100
                ElseIf jumbel >= 20 Then
                    TextBox6.Text = subtotal * 4 / 100
                End If
                subtotal = Val(TextBox5.Text)
                diskon = Val(TextBox6.Text)
                total = subtotal - diskon
                TextBox7.Text = total 'Sulthan
            End If
        End If
    End Sub

Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox8.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            total = Val(TextBox7.Text)
            bayar = Val(TextBox8.Text)
            kembali = bayar - total
            TextBox9.Text = kembali
            Me.TextBox9.Focus() 'Sulthan
        End If
    End Sub

Private Sub TextBox9_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox9.KeyPress
        If (e.KeyChar = Chr(13)) Then
            Me.Button1.Focus()
        End If
    End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = "" 'Sulthan
    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 Mau Keluar ??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Kasus 4



Code:

Public Class Form7
    Dim sks, jumlahsks, total, bayar, kembali As Integer

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            Me.TextBox2.Focus() 'Sulthan
        End If
    End Sub

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        e.Handled = CBool(keyascii)
        If e.KeyChar = Chr(13) Then
            Me.ComboBox1.Focus() 'Sulthan
        End If
    End Sub

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.ComboBox2.Focus()
        End If
    End Sub

Private Sub ComboBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox2.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        e.Handled = CBool(keyascii)
        If e.KeyChar = Chr(13) Then
            Me.TextBox4.Focus()
        End If
    End Sub

 Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox1.Text = "Karyawan" Then
            If ComboBox2.Text = "Akutansi" Then
                TextBox3.Text = 500000
            ElseIf ComboBox2.Text = "Manajemen" Then
                TextBox3.Text = 450000
            ElseIf ComboBox2.Text = "Informatika" Then
                TextBox3.Text = 400000
            ElseIf ComboBox2.Text = "Informasi" Then
                TextBox3.Text = 380000
            End If
        ElseIf ComboBox1.Text = "Reguler" Then
            If ComboBox2.Text = "Akutansi" Then
                TextBox3.Text = 450000
            ElseIf ComboBox2.Text = "Manajemen" Then
                TextBox3.Text = 400000
            ElseIf ComboBox2.Text = "Informatika" Then
                TextBox3.Text = 350000
            ElseIf ComboBox2.Text = "Informasi" Then
                TextBox3.Text = 330000
            End If
        End If
    End Sub

Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            sks = Val(TextBox3.Text)
            jumlahsks = Val(TextBox4.Text)
            total = sks * jumlahsks
            TextBox5.Text = total
            TextBox6.Focus()
        End If
    End Sub

Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            bayar = Val(TextBox6.Text)
            kembali = bayar - total
            TextBox7.Text = kembali
        End If
    End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = ""
        ComboBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
    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 Mau Keluar ??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Kasus 5




Code:

Public Class Form8
    Dim harga, beli, subtotal, diskon, total, bayar, kembali As Integer

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        Dim keyascii As Short = Asc(e.KeyChar)
        If (e.KeyChar Like "[A-Z,a-z]" _
            OrElse keyascii = Keys.Back _
            OrElse keyascii = Keys.Space _
            OrElse keyascii = Keys.Return _
            OrElse keyascii = Keys.Delete) Then
            keyascii = 0
        End If
        e.Handled = CBool(keyascii)
        If e.KeyChar = Chr(13) Then
            Me.ComboBox1.Focus() 'Sulthan
        End If
    End Sub

Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.ComboBox2.Focus()
        End If
    End Sub

Private Sub ComboBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox2.KeyPress
        If e.KeyChar = Chr(13) Then
            Me.TextBox3.Focus()
        End If
    End Sub

 Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox1.Text = "IMP" Then
            If ComboBox2.Text = "XL" Then
                TextBox2.Text = 250000
            ElseIf ComboBox2.Text = "L" Then
                TextBox2.Text = 240000
            ElseIf ComboBox2.Text = "M" Then
                TextBox2.Text = 230000
            End If
        ElseIf ComboBox1.Text = "Prada" Then
            If ComboBox2.Text = "XL" Then
                TextBox2.Text = 170000
            ElseIf ComboBox2.Text = "L" Then
                TextBox2.Text = 160000
            ElseIf ComboBox2.Text = "M" Then
                TextBox2.Text = 150000
            End If
        ElseIf ComboBox1.Text = "Gucci" Then
            If ComboBox2.Text = "XL" Then
                TextBox2.Text = 280000
            ElseIf ComboBox2.Text = "L" Then
                TextBox2.Text = 270000
            ElseIf ComboBox2.Text = "M" Then
                TextBox2.Text = 260000
            End If
        ElseIf ComboBox1.Text = "Louis" Then
            If ComboBox2.Text = "XL" Then
                TextBox2.Text = 360000
            ElseIf ComboBox2.Text = "L" Then
                TextBox2.Text = 350000
            ElseIf ComboBox2.Text = "M" Then
                TextBox2.Text = 340000
            End If
        ElseIf ComboBox1.Text = "Denim" Then
            If ComboBox2.Text = "XL" Then
                TextBox2.Text = 130000
            ElseIf ComboBox2.Text = "L" Then
                TextBox2.Text = 120000
            ElseIf ComboBox2.Text = "M" Then
                TextBox2.Text = 110000
            End If
        End If
    End Sub

Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            harga = Val(TextBox2.Text)
            beli = Val(TextBox3.Text)
            subtotal = harga * beli
            TextBox4.Text = subtotal
            Dim jumdis As Integer = TextBox3.Text
            Select Case jumdis
                Case 1 To 20
                    TextBox5.Text = subtotal * 5 / 100
                Case 21 To 50
                    TextBox5.Text = subtotal * 10 / 100
            End Select
            diskon = Val(TextBox5.Text)
            total = subtotal - diskon
            TextBox6.Text = total
            Me.TextBox7.Focus()
        End If
    End Sub

Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
        If (e.KeyChar = Chr(13)) Then
            total = Val(TextBox6.Text)
            bayar = Val(TextBox7.Text)
            kembali = bayar - total
            TextBox8.Text = kembali
        End If
    End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        ComboBox1.Text = ""
        ComboBox2.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
    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 Mau Keluar ??", vbYesNo, "Konfirmasi")
        If pesan = vbYes Then
            Close()
            End
        End If
    End Sub
End Class

Tidak ada komentar:

Posting Komentar

Visual Basic Lanjutan (Praktikum 6) - Object Oriented Programming (OOP)

Assalamualaikum Wr.Wb. Masih Bersama Saya Sulthan Alawy Shihab, Apakabar semua,saya harap anda sehat yaa dan semoga kita selalu dilin...