Membuat Form Dengan
Menggunakan Procedure & Function
Pada project 3 ini membandingkan program yang menggunakan Procedure & Function dan yang tidak menggunakan Procedure & Function
Form yang menggunakan Procedure & Function
Code Program :
Dim HrgMakanan As Long
Dim HrgMinuman As Long
Dim PrsMakanan As Integer
Dim PrsMinuman As Integer
Dim Total As Long
Dim Sisa As Long
Dim TotalHarga As Long
Dim Bayar As Long
-----------------------------------------------------------------------------------------------------------------------------------
Function Hitung()
Total = HrgMakanan * PrsMakanan +
HrgMinuman * PrsMinuman
End Function
-----------------------------------------------------------------------------------------------------------------------------------
Function Kembalian()
Sisa = Bayar -
TotalHarga
End Function
-----------------------------------------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
HrgMakanan = LHrgMakanan.Caption
HrgMinuman = LHrgMinuman.Caption
PrsMakanan = Txt_PrsMakanan.Text
PrsMinuman = Txt_PrsMinuman.Text
Call Hitung
LHitung.Caption = Total
Txt_TotalHarga = Total
End Sub
-----------------------------------------------------------------------------------------------------------------------------------
Private Sub Command2_Click()
TotalHarga = Txt_TotalHarga.Text
Bayar = Txt_Bayar.Text
Call Kembalian
LKembalian = Sisa
End Sub
-----------------------------------------------------------------------------------------------------------------------------------
Private Sub
Check1_Click()
If
Check1.Enabled = False Then
Combo2.Visible = False
ElseIf Check1.Enabled = True Then
Combo2.Visible = True
Else
LHrgMinuman.Visible = True
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Sub Menu_Makanan()
If Combo1.Text = "Nasi Goreng"
Then
LHrgMakanan.Caption = 15000
ElseIf Combo1.Text = "Bakso Urat"
Then
LHrgMakanan.Caption = 14000
ElseIf Combo1.Text = "Bakso
Telor" Then
LHrgMakanan.Caption = 12000
ElseIf Combo1.Text = "Mie
Ayam" Then
LHrgMakanan.Caption = 10000
ElseIf Combo1.Text = "Sate
Ayam" Then
LHrgMakanan.Caption = 15000
ElseIf Combo1.Text = "Soto"
Then
LHrgMakanan.Caption = 12000
ElseIf Combo1.Text = "Nasi
Uduk" Then
LHrgMakanan.Caption = 10000
ElseIf Combo1.Text = "Ayam
Geprek" Then
LHrgMakanan.Caption = 12000
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub
Combo1_Click()
Call
Menu_Makanan
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Sub Menu_Minuman()
If Combo2.Text
= "Es Teh Manis" Then
LHrgMinuman.Caption
= 3000
ElseIf
Combo2.Text = "Kopi" Then
LHrgMinuman.Caption
= 3000
ElseIf
Combo2.Text = "Es Jeruk" Then
LHrgMinuman.Caption
= 5000
ElseIf
Combo2.Text = "Es Campur" Then
LHrgMinuman.Caption
= 8000
ElseIf
Combo2.Text = "Teh Botol" Then
LHrgMinuman.Caption
= 4000
ElseIf
Combo2.Text = "Aqua" Then
LHrgMinuman.Caption
= 3000
ElseIf
Combo2.Text = "Jus Jeruk" Then
LHrgMinuman.Caption
= 7000
ElseIf
Combo2.Text = "Jus Alpukat" Then
LHrgMinuman.Caption
= 7000
ElseIf
Combo2.Text = "Jus Mangga" Then
LHrgMinuman.Caption
= 7000
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub
Combo2_Click()
Call Menu_Minuman
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub
Command3_Click()
Call MsgBox1
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Sub MsgBox1()
MsgBox Ljam.Caption +
vbCrLf + Ltanggal.Caption + vbCrLf + vbCrLf + "Makanan : " +
Combo1.Text + " " + "X" + " " +
Txt_PrsMakanan.Text + vbCrLf + "Harga : " + LHrgMakanan.Caption +
vbCrLf + "Minuman : " + Combo2.Text + " " + "X" +
" " + Txt_PrsMinuman.Text + vbCrLf + "Harga : " + LHrgMinuman.Caption
+ vbCrLf + "Total Harga : " + Txt_TotalHarga.Text + vbCrLf +
"Pembayaran : " + Txt_Bayar.Text + vbCrLf + "Kembalian : "
+ LKembalian.Caption
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Command4_Click()
Call Bersih
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Sub Bersih()
Combo1.Text =
""
Combo2.Text =
""
Check1.Value =
False
LHrgMakanan.Caption
= ""
LHrgMinuman.Caption
= ""
LHitung.Caption
= ""
LKembalian.Caption
= ""
Txt_PrsMakanan.Text
= ""
Txt_PrsMinuman.Text
= ""
Txt_TotalHarga.Text
= ""
Txt_Bayar.Text
= ""
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Command5_Click()
Dim Tutup As String
Tutup = MsgBox("Anda Yakin Ingin
Keluar?", vbQuestion + vbYesNo, "Question")
If Tutup = vbYes Then
End
Else
Form1.SetFocus
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Timer1_Timer()
Ljam = Time
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Timer2_Timer()
Ltanggal = Format(Now, "dddd, ddd
mm yyyy")
End Sub
Form yang tidak menggunakan Procedure & Function
Code Program :
Private Sub Check1_Click()
If Check1.Enabled = False Then
Combo2.Visible = False
ElseIf Check1.Enabled = True Then
Combo2.Visible = True
Else
LHrgMinuman.Visible = True
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub
Combo1_Click()
If Combo1.Text
= "Nasi Goreng" Then
LHrgMakanan.Caption
= 15000
ElseIf
Combo1.Text = "Bakso Urat" Then
LHrgMakanan.Caption
= 14000
ElseIf
Combo1.Text = "Bakso Telor" Then
LHrgMakanan.Caption
= 12000
ElseIf
Combo1.Text = "Mie Ayam" Then
LHrgMakanan.Caption
= 10000
ElseIf
Combo1.Text = "Sate Ayam" Then
LHrgMakanan.Caption
= 15000
ElseIf
Combo1.Text = "Soto" Then
LHrgMakanan.Caption
= 12000
ElseIf
Combo1.Text = "Nasi Uduk" Then
LHrgMakanan.Caption
= 10000
ElseIf
Combo1.Text = "Ayam Geprek" Then
LHrgMakanan.Caption
= 12000
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Combo2_Click()
If Combo2.Text = "Es Teh
Manis" Then
LHrgMinuman.Caption = 3000
ElseIf Combo2.Text = "Kopi"
Then
LHrgMinuman.Caption = 3000
ElseIf Combo2.Text = "Es
Jeruk" Then
LHrgMinuman.Caption = 5000
ElseIf Combo2.Text = "Es
Campur" Then
LHrgMinuman.Caption = 8000
ElseIf Combo2.Text = "Teh
Botol" Then
LHrgMinuman.Caption = 4000
ElseIf Combo2.Text = "Aqua"
Then
LHrgMinuman.Caption = 3000
ElseIf Combo2.Text = "Jus
Jeruk" Then
LHrgMinuman.Caption = 7000
ElseIf Combo2.Text = "Jus
Alpukat" Then
LHrgMinuman.Caption = 7000
ElseIf Combo2.Text = "Jus
Mangga" Then
LHrgMinuman.Caption = 7000
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Command1_Click()
LHitung.Caption =
(Val(LHrgMakanan.Caption) * Val(Txt_PrsMakanan.Text)) +
(Val(LHrgMinuman.Caption) * Val(Txt_PrsMinuman.Text))
Txt_TotalHarga.Text = LHitung.Caption
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Command2_Click()
LKembalian.Caption =
(Val(Txt_Bayar.Text) - Val(Txt_TotalHarga.Text))
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub
Command3_Click()
MsgBox (Ljam.Caption +
vbCrLf + Ltanggal.Caption + vbCrLf + vbCrLf + "Makanan : " +
Combo1.Text + " " + "X" + " " +
Txt_PrsMakanan.Text + vbCrLf + "Harga : " + LHrgMakanan.Caption +
vbCrLf + "Minuman : " + Combo2.Text + " " + "X" +
" " + Txt_PrsMinuman.Text + vbCrLf + "Harga : " +
LHrgMinuman.Caption + vbCrLf + "Total Harga : " + Txt_TotalHarga.Text
+ vbCrLf + "Pembayaran : " + Txt_Bayar.Text + vbCrLf +
"Kembalian : " + LKembalian.Caption)
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Command4_Click()
Combo1.Text = ""
Combo2.Text = ""
Check1.Value = False
LHrgMakanan.Caption = ""
LHrgMinuman.Caption = ""
LHitung.Caption = ""
LKembalian.Caption = ""
Txt_PrsMakanan.Text = ""
Txt_PrsMinuman.Text = ""
Txt_TotalHarga.Text = ""
Txt_Bayar.Text = ""
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub Command5_Click()
Pesan = MsgBox("Tutup Form
Pemesanan?", vbQuestion + vbYesNo, "Question")
If Pesan = vbYes Then
End
Else
Form1.SetFocus
End If
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub
Timer1_Timer()
Ljam.Caption =
Time
End Sub
------------------------------------------------------------------------------------------------------------------------------------
Private Sub
Timer2_Timer()
Ltanggal.Caption
= Format(Now, "dddd, dd mm yyyy")
End Sub
Meski program ini banyak kekurangan, semoga program ini bermanfaat :)
Komentar
Posting Komentar