1.Pada jendela tulis kode dibawah
ini
Dim angka(1 To 2) As Single
Dim operator As String
2.CommandButton angka [1-9]
[,]dengan kode dibawah ini
Private Sub cmdAngka_Click(Index As Integer)
Text1.Text =
Text1.Text & cmdAngka(Index).Caption
End Sub
3.CommandButton Hapus [C]
Private Sub cmdHapus_Click()
Text1.Text =
""
End Sub
4.CommandButton untuk operator
[+,-,/,*]
Private Sub cmdOperator_Click(Index As Integer)
If Text1.Text =
"" Then Exit Sub
angka(1) =
CSng(Text1.Text)
operator =
cmdOperator(Index).Caption
Text1.Text =
""
End Sub
5.CommandButton untuk hitung
[=]tulis kode dibawah ini
Private Sub cmdHitung_Click()
Dim hasil As
Single
If Text1.Text =
"" Then Exit Sub
angka(2) =
CSng(Text1.Text)
Select Case
operator
Case "+"
hasil =
angka(1) + angka(2)
Case "-"
hasil =
angka(1) - angka(2)
Case "*"
hasil =
angka(1) * angka(2)
Case "/"
hasil =
angka(1) / angka(2)
End Select
Text1.Text = hasil
End Sub
-----------------------------------------------------------------------------------------------
1.Pada jendela
tulis kode seperti dibawah ini
Private Sub Form_Load()
List1.AddItem "Disket"
List1.AddItem "Buku"
List1.AddItem "Kertas"
List1.AddItem "Pulpen"
End Sub
2.Buat 1 CommandButton1 [OK] ,
List1, 5 Label yang berisi nama barang, harga (Currency), jumlah, diskon, total
(Currency) & 1 TexBox untuk input jumlah barang kemudian tulis kode dibawah
ini
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 "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.1
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
Tidak ada komentar:
Posting Komentar