Rabu, 25 Maret 2020

Visual Lanjutan PRAKTEK 2 Kasus 3(If-Then-Else)


Public Class kasus3
    'RAFIF KARUNIA RAHMAN 2017230174
    Dim harga, jumlah, subtotal, diskon, tagihan, 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
            TextBox2.Focus()
        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
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
        ComboBox1.Text = ""
    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
            TextBox3.Focus()
        End If
        e.Handled = CBool(keyascii)
    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 'hanya bisa menginput angka
        If (e.KeyChar = Chr(13)) Then
            TextBox4.Focus()
        End If
    End Sub
    'nadiahtami 2017230007
    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 'hanya bisa menginput angka
        If (e.KeyChar = Chr(13)) Then
            harga = TextBox3.Text
            jumlah = TextBox4.Text
            TextBox5.Text = harga * jumlah
            TextBox5.Focus()
        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 'hanya bisa menginput angka
        If (e.KeyChar = Chr(13)) Then
            subtotal = TextBox5.Text
            If jumlah >= 100 Then
                diskon = subtotal * (10 / 100)
            ElseIf jumlah >= 50 And jumlah <= 100 Then
                diskon = subtotal * (7 / 100)
            ElseIf jumlah >= 20 And jumlah <= 50 Then
                diskon = subtotal * (4 / 100)
            Else
                diskon = 0
            End If
            TextBox6.Text = diskon
            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 'hanya bisa menginput angka
        If (e.KeyChar = Chr(13)) Then
            subtotal = TextBox5.Text
            diskon = TextBox6.Text
            tagihan = subtotal - diskon
            TextBox7.Focus()
        End If
        TextBox7.Text = tagihan
    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 'hanya bisa menginput angka
        If (e.KeyChar = Chr(13)) Then
            bayar = TextBox8.Text
            diskon = TextBox6.Text
            kembali = bayar - tagihan
            TextBox9.Focus()
        End If
        TextBox9.Text = kembali
    End Sub

    Private Sub kasus3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Tidak ada komentar:

Posting Komentar