Kasus 1 menggunakan Percabangan IF-Then-Else
Berikut Source Codenya :
Public Class kasus1
Dim kd, nama, kategori As String
Dim harga, jumlah, subtotal, diskon, total, bayar, kembali As Integer
'nadiahtami 2017230007
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 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 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
End If
If (e.KeyChar = Chr(13)) Then
TextBox5.Focus()
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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
bayar = TextBox8.Text
total = TextBox7.Text
TextBox9.Text = bayar - total
End If
If (e.KeyChar = Chr(13)) Then
TextBox9.Focus()
End If
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
subtotal = TextBox5.Text
If subtotal >= 100000 Then
TextBox6.Text = subtotal * (5 / 100)
Else
TextBox6.Text = 0
End If
If (e.KeyChar = Chr(13)) Then
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
TextBox7.Text = subtotal - diskon
End If
If (e.KeyChar = Chr(13)) Then
TextBox7.Focus()
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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
TextBox4.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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
TextBox8.Focus()
End If
End Sub
End Class
Kasus 2 menggunakan Percabangan IF-Then-Else
Berikut Source Codenya :
Public Class kasus2
Dim hadir, tugas, uts, uas, akhir As Integer
Dim grade, keterangan As String
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 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 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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
TextBox2.Focus()
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
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
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
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
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
uas = TextBox6.Text
uts = TextBox5.Text
tugas = TextBox4.Text
hadir = TextBox3.Text
TextBox7.Text = (hadir * (20 / 100)) + (tugas * (25 / 100)) + (uts * (25 / 100)) + (uas * (30 / 100))
TextBox7.Focus()
End If
End Sub
Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
akhir = TextBox7.Text
If akhir >= 84 And akhir <= 100 Then
grade = "A"
ElseIf akhir >= 64 And akhir <= 83 Then
grade = "B"
ElseIf akhir >= 50 And akhir <= 63 Then
grade = "C"
ElseIf akhir <= 50 Then
grade = "D"
End If
TextBox8.Text = grade
If (e.KeyChar = Chr(13)) Then
TextBox8.Focus()
End If
End Sub
'nadiahtami 2017230007
Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox8.KeyPress
grade = TextBox8.Text
If grade = "A" Then
keterangan = "Memuaskan"
ElseIf grade = "B" Then
keterangan = "Baik"
ElseIf grade = "C" Then
keterangan = "Cukup"
ElseIf grade = "D" Then
keterangan = "Gagal"
End If
TextBox9.Text = keterangan
If (e.KeyChar = Chr(13)) Then
TextBox9.Focus()
End If
End Sub
End Class
Public Class kasus2
Dim hadir, tugas, uts, uas, akhir As Integer
Dim grade, keterangan As String
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 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 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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
TextBox2.Focus()
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
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
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
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
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
uas = TextBox6.Text
uts = TextBox5.Text
tugas = TextBox4.Text
hadir = TextBox3.Text
TextBox7.Text = (hadir * (20 / 100)) + (tugas * (25 / 100)) + (uts * (25 / 100)) + (uas * (30 / 100))
TextBox7.Focus()
End If
End Sub
Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
akhir = TextBox7.Text
If akhir >= 84 And akhir <= 100 Then
grade = "A"
ElseIf akhir >= 64 And akhir <= 83 Then
grade = "B"
ElseIf akhir >= 50 And akhir <= 63 Then
grade = "C"
ElseIf akhir <= 50 Then
grade = "D"
End If
TextBox8.Text = grade
If (e.KeyChar = Chr(13)) Then
TextBox8.Focus()
End If
End Sub
'nadiahtami 2017230007
Private Sub TextBox8_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox8.KeyPress
grade = TextBox8.Text
If grade = "A" Then
keterangan = "Memuaskan"
ElseIf grade = "B" Then
keterangan = "Baik"
ElseIf grade = "C" Then
keterangan = "Cukup"
ElseIf grade = "D" Then
keterangan = "Gagal"
End If
TextBox9.Text = keterangan
If (e.KeyChar = Chr(13)) Then
TextBox9.Focus()
End If
End Sub
End Class
Kasus 3 menggunakan Percabangan IF-Then-Else
Berikut Source Codenya :
Public Class kasus3
'nadiahtami 2017230007
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
End Class
Kasus 4 menggunakan Percabangan Nested-If
Berikut Source Codenya :
Public Class kasus4
'nadiahtami 2017230007
Dim sks, jumlah, tagihan, bayar, kembali As Integer
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 = ""
ComboBox1.Text = ""
ComboBox2.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 Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub ComboBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox2.KeyPress
If ComboBox1.Text = "Reguler" Then
If ComboBox2.Text = "Akuntansi" Then
sks = 450000
ElseIf ComboBox2.Text = "Manajemen" Then
sks = 400000
ElseIf ComboBox2.Text = "Teknik Informatika" Then
sks = 350000
ElseIf ComboBox2.Text = "Sistem Informasi" Then
sks = 330000
End If
ElseIf ComboBox1.Text = "Karyawan" Then
If ComboBox2.Text = "Akuntansi" Then
sks = 500000
ElseIf ComboBox2.Text = "Manajemen" Then
sks = 450000
ElseIf ComboBox2.Text = "Teknik Informatika" Then
sks = 400000
ElseIf ComboBox2.Text = "Sistem Informasi" Then
sks = 380000
End If
End If
TextBox3.Text = sks
End Sub
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 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
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
sks = TextBox3.Text
jumlah = TextBox4.Text
TextBox5.Text = sks * jumlah
TextBox5.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
tagihan = TextBox5.Text
bayar = TextBox6.Text
TextBox7.Text = bayar - tagihan
TextBox7.Focus()
End If
End Sub
End Class
Public Class kasus4
'nadiahtami 2017230007
Dim sks, jumlah, tagihan, bayar, kembali As Integer
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 = ""
ComboBox1.Text = ""
ComboBox2.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 Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
End If
End Sub
Private Sub ComboBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox2.KeyPress
If ComboBox1.Text = "Reguler" Then
If ComboBox2.Text = "Akuntansi" Then
sks = 450000
ElseIf ComboBox2.Text = "Manajemen" Then
sks = 400000
ElseIf ComboBox2.Text = "Teknik Informatika" Then
sks = 350000
ElseIf ComboBox2.Text = "Sistem Informasi" Then
sks = 330000
End If
ElseIf ComboBox1.Text = "Karyawan" Then
If ComboBox2.Text = "Akuntansi" Then
sks = 500000
ElseIf ComboBox2.Text = "Manajemen" Then
sks = 450000
ElseIf ComboBox2.Text = "Teknik Informatika" Then
sks = 400000
ElseIf ComboBox2.Text = "Sistem Informasi" Then
sks = 380000
End If
End If
TextBox3.Text = sks
End Sub
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 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
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
sks = TextBox3.Text
jumlah = TextBox4.Text
TextBox5.Text = sks * jumlah
TextBox5.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
tagihan = TextBox5.Text
bayar = TextBox6.Text
TextBox7.Text = bayar - tagihan
TextBox7.Focus()
End If
End Sub
End Class
Kasus 5 menggunakan Percabangan Nested-If
Berikut Source Codenya :
Public Class kasus5
Dim merk, ukuran As String
Dim harga, jumlah, subtotal, diskon, tagihan, bayar, kembali As Integer
'Nadiahtami 2017230007'
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
If (e.KeyChar = Chr(13)) Then
ComboBox1.Focus()
End If
e.Handled = CBool(keyascii)
End Sub
Private Sub ComboBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox2.KeyPress
If ComboBox1.Text = "IMP" Then
If ComboBox2.Text = "XL" Then
harga = 250000
ElseIf ComboBox2.Text = "L" Then
harga = 240000
ElseIf ComboBox2.Text = "M" Then
harga = 230000
End If
ElseIf ComboBox1.Text = "Prada" Then
If ComboBox2.Text = "XL" Then
harga = 170000
ElseIf ComboBox2.Text = "L" Then
harga = 160000
ElseIf ComboBox2.Text = "M" Then
harga = 150000
End If
ElseIf ComboBox1.Text = "Gucci" Then
If ComboBox2.Text = "XL" Then
harga = 280000
ElseIf ComboBox2.Text = "L" Then
harga = 270000
ElseIf ComboBox2.Text = "M" Then
harga = 260000
End If
ElseIf ComboBox1.Text = "Loius" Then
If ComboBox2.Text = "XL" Then
harga = 360000
ElseIf ComboBox2.Text = "L" Then
harga = 350000
ElseIf ComboBox2.Text = "M" Then
harga = 340000
End If
ElseIf ComboBox1.Text = "Denim" Then
If ComboBox2.Text = "XL" Then
harga = 130000
ElseIf ComboBox2.Text = "L" Then
harga = 120000
ElseIf ComboBox2.Text = "M" Then
harga = 110000
End If
End If
TextBox2.Text = harga
TextBox2.Focus()
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.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
TextBox3.Focus()
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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
harga = TextBox2.Text
jumlah = TextBox3.Text
TextBox4.Text = harga * jumlah
TextBox4.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 = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
ComboBox1.Text = ""
ComboBox2.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 Ingin Keluar??", vbYesNo, "Konfirmasi")
If pesan = vbYes Then
End
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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
subtotal = TextBox4.Text
If subtotal >= 1000000 Then
diskon = subtotal * (10 / 100)
ElseIf subtotal >= 500000 And jumlah <= 1000000 Then
diskon = subtotal * (7 / 100)
ElseIf subtotal >= 200000 And jumlah <= 500000 Then
diskon = subtotal * (4 / 100)
Else
diskon = 0
End If
TextBox5.Text = diskon
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 = TextBox4.Text
diskon = TextBox5.Text
tagihan = subtotal - diskon
TextBox6.Focus()
End If
TextBox6.Text = tagihan
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 'hanya bisa menginput angka
If (e.KeyChar = Chr(13)) Then
tagihan = TextBox6.Text
bayar = TextBox7.Text
TextBox8.Text = bayar - tagihan
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
TextBox7.Focus()
End If
End Sub
End Class
Komentar
Posting Komentar