Contoh Kasus Percabangan pada Visual Basic 2010 2
Post ini adalah lanjutan dari materi Nested If Percabangan
untuk materi lainnya dapat dilihat disini
- Tipe Data dan Variabel pada Visual Basic
- Local, Global Variabe, Structure dan Konversi Data pada Visual Basic
- Operator pada Visual Basic
- Percabangan pada Visual Basic
- Lanjutan Percabangan pada Visual Basic
- Percabangan pada Visual Basic 2
- Percabangan pada Visual Basic Select - Case
- Perulangan pada Visual Basic
- Perulangan pada Visual Basic 2
- Perulangan pada Visual Basic 3
- Array di Visual Basic
- Array Dua Dimensi
- Kasus 4 (Kasus 1 ada disini)
Buatlah form seperti dibawah ini
• Kelas dan Jurusan dipilih, biaya/sks akan muncul sesuai penyeleksian kondisi.
• Gunakan Event Keypress untuk input dan Validasi utk huruf dan angka.
• Ketika di enter di textboxt jumlah sks, total tagihan akan muncul.
• Total tagihan = biaya/sks * jumlah sks
• Uang Bayar diinput, ketika di enter uang kembali akan muncul.
Source Code :
Public Class Pertemuan_2_Kasus_4_Teori
Public totaltagihan, biayasks, jumlahsks, uangbayar, uangkembali As Double
Private Sub Pertemuan_2_Kasus_4_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "salmantech12.blogspot.com"
cbkelas.Items.Add("Reguler")
cbkelas.Items.Add("Karyawan")
cbjurusan.Items.Add("Akuntansi")
cbjurusan.Items.Add("Manajemen")
cbjurusan.Items.Add("Teknik Informatika")
cbjurusan.Items.Add("Sistem Informasi")
End Sub
Private Sub cbjurusan_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbjurusan.DropDownClosed
tbjumlahsks.Focus()
End Sub
Private Sub cbjurusan_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbjurusan.SelectedIndexChanged
If cbkelas.Text = "Reguler" Then
If cbjurusan.Text = "Akuntansi" Then
tbbiayasks.Text = 450000
ElseIf cbjurusan.Text = "Manajemen" Then
tbbiayasks.Text = 400000
'Ahmad Salman Farisi
ElseIf cbjurusan.Text = "Teknik Informatika" Then
tbbiayasks.Text = 350000
'2017230184
ElseIf cbjurusan.Text = "Sistem Informasi" Then
tbbiayasks.Text = 330000
End If
ElseIf cbkelas.Text = "Karyawan" Then
If cbjurusan.Text = "Akuntansi" Then
tbbiayasks.Text = 500000
ElseIf cbjurusan.Text = "Manajemen" Then
tbbiayasks.Text = 450000
ElseIf cbjurusan.Text = "Teknik Informatika" Then
tbbiayasks.Text = 400000
ElseIf cbjurusan.Text = "Sistem Informasi" Then
tbbiayasks.Text = 380000
End If
End If
End Sub
Private Sub tbjumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbjumlahsks.KeyPress
If e.KeyChar = Chr(13) Then
biayasks = tbbiayasks.Text
jumlahsks = tbjumlahsks.Text
totaltagihan = biayasks * jumlahsks
tbtagihan.Text = totaltagihan
tbuangbayar.Focus()
End If
End Sub
Private Sub tbuangbayar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbuangbayar.KeyPress
If e.KeyChar = Chr(13) Then
uangbayar = tbuangbayar.Text
totaltagihan = tbtagihan.Text
uangkembali = uangbayar - totaltagihan
tbuangkembali.Text = "Rp. " + uangkembali.ToString
End If
End Sub
Private Sub tbnoinduk_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbnoinduk.KeyPress
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
If e.KeyChar = Chr(13) Then
tbnama.Focus()
End If
End Sub
Private Sub tbnama_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbnama.KeyPress
Dim allowedChars As String = "abcdefghijklmnopqrstuvwxyz "
If Not (Asc(e.KeyChar) = 8) Then
If e.KeyChar = Chr(13) Then
cbkelas.DroppedDown = True
End If
If Not allowedChars.Contains(e.KeyChar.ToString.ToLower) Then
e.KeyChar = ChrW(0)
e.Handled = True
End If
End If
End Sub
Private Sub cbkelas_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbkelas.DropDownClosed
cbjurusan.DroppedDown = True
End Sub
Private Sub btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclear.Click
tbbiayasks.Clear()
tbjumlahsks.Clear()
tbnama.Clear()
tbnoinduk.Clear()
tbtagihan.Clear()
tbuangbayar.Clear()
tbuangkembali.Clear()
cbjurusan.SelectedIndex = -1
cbkelas.SelectedIndex = -1
End Sub
Private Sub btexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btexit.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "salmantech12.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_2_Kasus_4_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "salmantech12.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
End Class
Berikut hasil programnya
- Kasus 5
Buatlah form seperti di bawah ini :
• Merk dan Ukuran Baju, harga akan muncul sesuai penyeleksian kondisi.
• Gunakan Event Keypress utk input dan Validasi utk huruf dan angka.
• Ketika di enter di jumlah beli, subtotal, diskon dan total tagihan akan muncul.
• Uang Bayar diinput, ketika di enter uang kembali akan muncul.
Source Code :
Public Class Pertemuan_2_Kasus_5_Teori
Public jumlahbeli, hargakaos, subtotal, diskon, totaltagihan, uangbayar, uangkembali As Double
Private Sub Pertemuan_2_Kasus_5_Teori_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "salmantech12.blogspot.com"
cbmerk.Items.Add("IMP")
cbmerk.Items.Add("Prada")
cbmerk.Items.Add("Gucci")
cbmerk.Items.Add("Loius")
cbmerk.Items.Add("Denim")
cbukuran.Items.Add("XL")
cbukuran.Items.Add("L")
cbukuran.Items.Add("M")
End Sub
Private Sub cbukuran_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbukuran.DropDownClosed
tbjumlahbeli.Focus()
End Sub
Private Sub cbukuran_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbukuran.SelectedIndexChanged
If cbmerk.Text = "IMP" Then
If cbukuran.Text = "XL" Then
tbharga.Text = 250000
ElseIf cbukuran.Text = "L" Then
tbharga.Text = 240000
ElseIf cbukuran.Text = "M" Then
tbharga.Text = 230000
End If
ElseIf cbmerk.Text = "Prada" Then
If cbukuran.Text = "XL" Then
tbharga.Text = 170000
ElseIf cbukuran.Text = "L" Then
tbharga.Text = 160000
ElseIf cbukuran.Text = "M" Then
tbharga.Text = 150000
End If
ElseIf cbmerk.Text = "Gucci" Then
If cbukuran.Text = "XL" Then
tbharga.Text = 280000
ElseIf cbukuran.Text = "L" Then
tbharga.Text = 270000
ElseIf cbukuran.Text = "M" Then
tbharga.Text = 260000
End If
ElseIf cbmerk.Text = "Loius" Then
If cbukuran.Text = "XL" Then
tbharga.Text = 360000
ElseIf cbukuran.Text = "L" Then
tbharga.Text = 350000
ElseIf cbukuran.Text = "M" Then
tbharga.Text = 340000
End If
ElseIf cbmerk.Text = "Denim" Then
If cbukuran.Text = "XL" Then
tbharga.Text = 130000
ElseIf cbukuran.Text = "L" Then
tbharga.Text = 120000
ElseIf cbukuran.Text = "M" Then
tbharga.Text = 110000
End If
End If
End Sub
Private Sub tbjumlahbeli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbjumlahbeli.KeyPress
If e.KeyChar = Chr(13) Then
jumlahbeli = tbjumlahbeli.Text
hargakaos = tbharga.Text
subtotal = hargakaos * jumlahbeli
tbsubtotal.Text = subtotal
tbdiskon.Text = "Tidak dapat diskon"
tbtotaltagihan.Text = subtotal
tbuangbayar.Focus()
If subtotal >= 300000 Then
diskon = subtotal * 0.1
tbdiskon.Text = diskon
tbsubtotal.Text = subtotal
totaltagihan = subtotal - diskon
tbtotaltagihan.Text = totaltagihan
tbuangbayar.Focus()
ElseIf subtotal >= 250000 Then
diskon = subtotal * 0.07
tbdiskon.Text = diskon
tbsubtotal.Text = subtotal
totaltagihan = subtotal - diskon
tbtotaltagihan.Text = totaltagihan
tbuangbayar.Focus()
ElseIf subtotal >= 200000 Then
diskon = subtotal * 0.04
tbdiskon.Text = diskon
tbsubtotal.Text = subtotal
totaltagihan = subtotal - diskon
tbtotaltagihan.Text = totaltagihan
tbuangbayar.Focus()
End If
End If
End Sub
Private Sub tbpembeli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbpembeli.KeyPress
Dim allowedChars As String = "abcdefghijklmnopqrstuvwxyz "
If Not (Asc(e.KeyChar) = 8) Then
If e.KeyChar = Chr(13) Then
cbmerk.DroppedDown = True
End If
If Not allowedChars.Contains(e.KeyChar.ToString.ToLower) Then
e.KeyChar = ChrW(0)
e.Handled = True
End If
End If
End Sub
Private Sub cbmerk_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbmerk.DropDownClosed
cbukuran.DroppedDown = True
End Sub
Private Sub btclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclear.Click
tbdiskon.Clear()
tbharga.Clear()
tbjumlahbeli.Clear()
tbpembeli.Clear()
tbsubtotal.Clear()
tbtotaltagihan.Clear()
tbuangbayar.Clear()
tbuangkembali.Clear()
cbmerk.SelectedIndex = -1
cbukuran.SelectedIndex = -1
End Sub
Private Sub tbuangbayar_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tbuangbayar.KeyPress
If e.KeyChar = Chr(13) Then
uangbayar = tbuangbayar.Text
totaltagihan = tbtotaltagihan.Text
uangkembali = uangbayar - totaltagihan
tbuangkembali.Text = "Rp." + uangkembali.ToString
End If
End Sub
Private Sub btexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btexit.Click
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "salmantech12.blogspot.com")
If pesan = vbYes Then
End
End If
End Sub
Private Sub Pertemuan_2_Kasus_5_Teori_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim pesan As String
pesan = MsgBox("Are you sure want to exit ?", vbYesNo, "salmantech12.blogspot.com")
If pesan = vbNo Then
e.Cancel = True
End If
End Sub
End Class
Berikut hasil programnya
Sekian untuk post kali ini semoga bermanfaat
どうもありがとうございました…!
Share post ini ke :
Facebook WhatsApp Twitter LINE Linkedin
0 Response to "Contoh Kasus Percabangan pada Visual Basic 2010 2 "
Post a Comment