Kita akan menggunakan control option dan check box juga frame. Buatlah sebuah project baru. Kita akan membangun sebuah form dimana sebuah pesanan pizza dapat dimasukkan dengan mudah hanya melalui klik pada checkbox dan option button.Setelah kita RUN maka akan tampil sebuah message box yang memeberikan informasi tentang pizza yang di pesan.
Buatlah sebuah form aplikasi berikut:
Buatlah sebuah form aplikasi berikut:
Ubah propertinya sebagai berikut:
Form1:
BorderStyle 1-Fixed Single
Caption Pizza Order
Name frmPizza
Frame1:
Caption Size
Frame2:
Caption Crust Type
Frame3
Caption Toppings
Option1:
Caption Small
Name optSize
Value True
Option2:
Caption Medium
Name optSize (yes, create a control array)
Option3:
Caption Large
Name optSize
Option4:
Caption Thin Crust
Name optCrust
Value True
Option5:
Caption Thick Crust
Name optCrust (yes, create a control array)
Option6:
Caption Eat In
Name optWhere
Value True
Option7:
Caption Take Out
Name optWhere (yes, create a control array)
Check1:
Caption Extra Cheese
Name chkTop
Check2:
Caption Mushrooms
Name chkTop (yes, create a control array)
Check3:
Caption Black Olives
Name chkTop
Check4:
Caption Onions
Name chkTop
Check5:
Caption Green Peppers
Name chkTop
Check6:
Caption Tomatoes
Name chkTop
Command1:
Caption &Build Pizza
Name cmdBuild
Command2:
Caption &Reset
Name cmdReset
Command3:
Caption E&xit
Name cmdExit
Harusnya tampilan form-nya akan kurang lebih seperti ini.
Codenya:
Dim PizzaSize As String
Dim PizzaCrust As String
Dim PizzaWhere As String
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdReset_Click()
Dim I As Integer
Dim H As Integer
'PizzaSize = "Small"
'PizzaCrust = "Thin Crust"
'PizzaWhere = "Eat In"
For H = 1 To 2
optSize(H).Value = False
Next H
For I = 0 To 5
chkTop(I).Value = Unchecked
Next I
optSize(0).Value = True
optCrust(0).Value = True
optWhere(0).Value = True
End Sub
Private Sub Form_Load()
'Initialize pizza parameters
PizzaSize = "Small"
PizzaCrust = "Thin Crust"
PizzaWhere = "Eat In"
End Sub
Private Sub optSize_Click(Index As Integer)
'Read pizza size
PizzaSize = optSize(Index).Caption
End Sub
Private Sub optCrust_Click(Index As Integer)
'Read crust type
PizzaCrust = optCrust(Index).Caption
End Sub
Private Sub optWhere_Click(Index As Integer)
'Read pizza eating location
PizzaWhere = optWhere(Index).Caption
End Sub
Private Sub cmdBuild_Click()
'This procedure builds a message box that displays yourpizza type
Dim Message As String
Dim I As Integer
Message = PizzaWhere + vbCr
Message = Message + PizzaSize + " Pizza" + vbCr
Message = Message + PizzaCrust + vbCr
For I = 0 To 5
If chkTop(I).Value = vbChecked Then Message = Message + chkTop(I).Caption + vbCr
Next I
If chkTop(0).Value = 0 And chkTop(1).Value = 0 And chkTop(2).Value = 0 And chkTop(3).Value = 0 And chkTop(3).Value = 0 Then
Message = Message + "Ordinary Cheese Only" + vbCr
End If
MsgBox Message, vbOKOnly, "Your Pizza"
End Sub
Coba RUN saja
Semoga jelas dan berguna bagi kita semua.
Jangan lupa, jika donwnload file project, langsung run dulu di VB Studio agar window form dan code keluar tanpa kita kebingungan.
Selamat belajar VB…:D
Tidak ada komentar:
Posting Komentar