Kali ini saya akan membagikan Cara Membuat Program Struktur Select... Case dengan Visual Basic 6.0
Download Program Struktur Select... Case Visual Basic 6.0
1. Buka Program Visual Basic 6.0
2. Desain Form seperti ini
3. Ubah Property
Form1-Caption-Struktur SELECT... CASE
Label1-Caption-Pilih Barang :
List1-Name-List1
Label2-Caption-JUmlah :
Text1-Text-<Kosong>
Command1-Caption-OK
Label3-Name-LblBarang
Label4-Name-LblHarga
Label5-Name-LblJumlah
Label6-Name-LblDiskon
Label7-Name- LblTotal
4. Copy code berikut lalu klik View Code dan pastekan
Private Sub Form_Load()
List1.AddItem "DVD RW"
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
If Not IsNumeric(Text1.Text) Then
MsgBox "Isi jumlah barang harus angka !!"
Text1.SetFocus
Exit Sub
End If
Select Case List1.Text
Case "DVD RW"
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
5. Jalankan Program dengan menekan F5, maka tampilannya akan seperti ini
Download Program Struktur Select... Case Visual Basic 6.0
Selamat Mencoba...!!!
No comments:
Post a Comment