Wednesday, May 4, 2011

Program Case...Of

Private Sub Form_Load()
List1.AddItem "Disket"
List1.AddItem "Buku"
List1.AddItem "Kertas"
List1.AddItem "Pulpen"
End Sub
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 jumlah barang !!"
Text1.SetFocus
Exit Sub
End If
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 Sub

0 komentar:

Post a Comment

Tinggalkan Komentar Disini