Pada postingan kali ini saya akan ngebahas tentang penggunaan struktur control select pada visual basic 6.0
Kira-kira udah pada tau belum ya apa itu struktur control ?hem kayaknya pada belum paham nie....Langsung aja ya menuju ke TKP...heehhehe
Struktur kontrol merupakan perintah dengan bentuk (struktur) tertentu yang digunakan untuk mengatur jalan nya program.
Sekarang langsung aja kita bahas struktur control select case pada visual basic 6.0...Adapun bentuk penulisan nya seperti di bawah ini.
SELECT CASE <pilihan1>
<blok kode program 1>
SELECT CASE <pilihan2>
<blok kode program 2>
SELECT CASE <pilihan3>
<blok kode program 3>
SELECT CASE <pilihan4>
<blok kode program 4>
Berikut source code program diatas
Private Sub Command1_Click()
Dim harga As Currency, total As Currency
Dim jumlah As Integer
Dim diskon As Single
Dim satuan As String
If List1.Text = "" Then
MsgBox "Anda belum memilih barang !!"
List1.ListIndex = 0
Exit Sub
End If
If Text1.Text = "" Then
MsgBox "Anda belum mengisi barang!!"
Text1.SetFocus
Exit Sub
Select Case List1.Text
Case "Disket"
harga = 35000
satuan = "Box"
Case "Buku"
harga = 20000
satuan = "Lusin"
Case "Kertas"
harga = 25000
satuan = "Rim"
Case "Pulpen"
harga = 10000
satuan = "Pak"
End Select
lblBarang.Caption = "Barang :" & List1.Text
lblHarga.Caption = "Harga :" & Format(harga, "currency") & "/" & satuan
lblJumlah.Caption = "Jumlah : " & Text1.Text & "" & satuan
jumlah = Text1.Text
Select Case jumlah
Case Is < 10
diskon = 0
Case 10 To 20
diskon = 0.15
Case Else
diskon = 0.2
End Select
total = jumlah * (harga * (1 - diskon))
lblDiskon.Caption = "Diskon :" & Format(diskon, "0%")
lblTotal.Caption = "Total Bayar :" & Format(total, "Currency")
End If
End Sub
Private Sub Form_Load()
List1.AddItem "Disket"
List1.AddItem "Buku"
List1.AddItem "Kertas"
List1.AddItem "Pulpen"
End Sub
Dim harga As Currency, total As Currency
Dim jumlah As Integer
Dim diskon As Single
Dim satuan As String
If List1.Text = "" Then
MsgBox "Anda belum memilih barang !!"
List1.ListIndex = 0
Exit Sub
End If
If Text1.Text = "" Then
MsgBox "Anda belum mengisi barang!!"
Text1.SetFocus
Exit Sub
Select Case List1.Text
Case "Disket"
harga = 35000
satuan = "Box"
Case "Buku"
harga = 20000
satuan = "Lusin"
Case "Kertas"
harga = 25000
satuan = "Rim"
Case "Pulpen"
harga = 10000
satuan = "Pak"
End Select
lblBarang.Caption = "Barang :" & List1.Text
lblHarga.Caption = "Harga :" & Format(harga, "currency") & "/" & satuan
lblJumlah.Caption = "Jumlah : " & Text1.Text & "" & satuan
jumlah = Text1.Text
Select Case jumlah
Case Is < 10
diskon = 0
Case 10 To 20
diskon = 0.15
Case Else
diskon = 0.2
End Select
total = jumlah * (harga * (1 - diskon))
lblDiskon.Caption = "Diskon :" & Format(diskon, "0%")
lblTotal.Caption = "Total Bayar :" & Format(total, "Currency")
End If
End Sub
Private Sub Form_Load()
List1.AddItem "Disket"
List1.AddItem "Buku"
List1.AddItem "Kertas"
List1.AddItem "Pulpen"
End Sub
Untuk contoh program dan source codenya download disini
izin sedot gan..
ReplyDeleteboleh gan silahkan sedot ja mak nyos hehehe
Delete