Rabu, 01 Oktober 2014

“Latihan Visual 1” dengan Visual Basic 6.0

VB6SP6_logo

Soal dan jawaban “Latihan Visual 1 (Vb6) ” yang terdapat pada blog Aziz Rahman.

Tidak banyak modifikasi yang dibuat. Hanya sekedar menambahkan fitur Diskon dan Harga yang harus dibayarkan setelah diskon. Untuk lebih lengkapnya dapat dilihat pada kode sumber yang disertakan.

 

 

Warung_Makan_Sederhana

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Warung Makan ""Pak Sueb"""
ClientHeight = 5655
ClientLeft = 45
ClientTop = 390
ClientWidth = 4710
BeginProperty Font
Name = "Segoe UI"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5655
ScaleWidth = 4710
StartUpPosition = 2 'CenterScreen
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 17
Top = 5280
Visible = 0 'False
Width = 4710
_ExtentX = 8308
_ExtentY = 661
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 1
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
EndProperty
EndProperty
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
Height = 375
Index = 4
Left = 2040
TabIndex = 14
Top = 2640
Width = 2415
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Segoe UI"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 5
Left = 2040
Locked = -1 'True
TabIndex = 13
Top = 3120
Width = 2415
End
Begin VB.CommandButton Command1
Caption = "Keluar"
Height = 495
Index = 2
Left = 240
TabIndex = 12
Top = 4920
Width = 4215
End
Begin VB.CommandButton Command1
Caption = "Baru"
Enabled = 0 'False
Height = 495
Index = 1
Left = 240
TabIndex = 11
Top = 4200
Width = 4215
End
Begin VB.CommandButton Command1
Caption = "Proses"
Enabled = 0 'False
Height = 495
Index = 0
Left = 240
TabIndex = 10
Top = 3600
Width = 4215
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
ForeColor = &H008080FF&
Height = 375
Index = 3
Left = 2040
Locked = -1 'True
TabIndex = 9
Top = 2160
Width = 2415
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
Height = 375
Index = 2
Left = 2040
TabIndex = 8
Top = 1680
Width = 2415
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
Height = 375
Index = 1
Left = 2040
Locked = -1 'True
TabIndex = 7
Top = 1200
Width = 2415
End
Begin VB.TextBox Text1
Height = 375
Index = 0
Left = 2040
Locked = -1 'True
TabIndex = 6
Top = 720
Width = 2415
End
Begin VB.ComboBox Combo1
Height = 345
Left = 2040
Style = 2 'Dropdown List
TabIndex = 5
Top = 240
Width = 2415
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Diskon:"
Height = 225
Index = 6
Left = 240
TabIndex = 16
Top = 2700
Width = 585
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Total Pembayaran:"
Height = 225
Index = 5
Left = 240
TabIndex = 15
Top = 3180
Width = 1485
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Jumlah Pembayaran:"
Height = 225
Index = 4
Left = 240
TabIndex = 4
Top = 2220
Width = 1650
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Jumlah Pembelian:"
Height = 225
Index = 3
Left = 240
TabIndex = 3
Top = 1740
Width = 1500
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Harga:"
Height = 225
Index = 2
Left = 240
TabIndex = 2
Top = 1280
Width = 525
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Nama Makanan:"
Height = 225
Index = 1
Left = 240
TabIndex = 1
Top = 780
Width = 1305
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Kode Makanan:"
Height = 225
Index = 0
Left = 240
TabIndex = 0
Top = 280
Width = 1230
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Harga_Makanan As Currency

Private Sub Combo1_Click()
Dim Nama_Makanan As String
Select Case Combo1.Text
Case "STA"
Nama_Makanan = "Soto Ayam"
Harga_Makanan = 10000
Case "STD"
Nama_Makanan = "Soto Daging"
Harga_Makanan = 12000
Case "BSR"
Nama_Makanan = "Baso Rudal"
Harga_Makanan = 13000
Case "MAS"
Nama_Makanan = "Mie Ayam Special"
Harga_Makanan = 11000
End Select

Text1(0).Text = Nama_Makanan
Text1(1).Text = Format(Harga_Makanan, "Currency") & "/Porsi"
Text1(2).SetFocus
End Sub

Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0:
Dim Jumlah_Bayar, Total_Semua As Currency
Dim Jumlah_Pembelian As Integer
Dim Diskon As Single

Jumlah_Bayar = Val(Text1(2).Text) * Harga_Makanan
Text1(3).Text = Format(Jumlah_Bayar, "Currency")

Jumlah_Pembelian = Val(Text1(2).Text)

Select Case Jumlah_Pembelian
Case Is < 10
Diskon = 0
Case 10 To 20
Diskon = 0.05
Case Else
Diskon = 0.1
End Select

Total_Semua = Jumlah_Pembelian * (Harga_Makanan * (1 - Diskon))
Text1(4).Text = Format(Diskon, "0 %")
Text1(5).Text = Format(Total_Semua, "Currency")

Command1(Index).Enabled = False
Command1(1).Enabled = True
Command1(1).SetFocus
Case 1:
Dim i%
For i = 0 To 5
Text1(i).Text = Empty
Next
Combo1.Clear
Form_Load
Command1(Index).Enabled = False
Case 2:
Dim Respon
Respon = MsgBox("Keluar program ?", _
vbQuestion + vbYesNo, _
"Perhatian")
If Respon = vbYes Then
End
End If
End Select
End Sub

Private Sub Form_Load()
Combo1.AddItem "STA"
Combo1.AddItem "STD"
Combo1.AddItem "BSR"
Combo1.AddItem "MAS"
End Sub

Private Sub Text1_Change(Index As Integer)
If Text1(2).Text = Empty Then
Command1(0).Enabled = False
Else
Command1(0).Enabled = True
End If
End Sub

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or _
KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
Beep
KeyAscii = 0
End If

If (KeyAscii = 13) Then
Command1_Click (0)
End If
End Sub



Unduh Kode Sumber

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda