We had just learned about programming with Microsoft Visual Basic 6.0 and tried to create two Windows applications (using Visual Basic 6.0), the first one was "Stop Watch" and the second was "Calendar/Time". Some people have told me, the teacher, that it is interesting and challenging, while some other people have never said any word but have just thought that it is boring. Yes, the teacher realizes that programming is so valuable because it can develop anyone both systematic thinking and solving. Well, the teacher knows that anybody can never hand on it if he is not interested in programming. But, now the teaching is not over, the show must go on!
"Pizza Order" Application
SOURCE : www.kidwares.com
1. Start a new project. We'll build a form where a pizza order can be entered by simply clicking on check boxes and option buttons.
2. Draw three frames. In the first, draw three option buttons, in the second, draw two option buttons, and in the third, draw six check boxes. Draw two option buttons on the form. Add two command buttons. Make things look something like this.
3. Set the properties of the form and each control.
Caption Pizza Order
Name frmPizza
Name optSize
Value True
Name optSize (yes, create a control array)
Name optSize
Name optCrust
Value True
Name optCrust (yes, create a control array)
Name optWhere
Value True
Name optWhere (yes, create a control array)
Name chkTop
Name chkTop (yes, create a control array)
Name chkTop
Name chkTop
Name chkTop
Name chkTop
Name cmdBuild
Name cmdExit
4. Declare the following variables in the general declarations area:
Option Explicit
Dim PizzaSize As String
Dim PizzaCrust As String
Dim PizzaWhere As String
5. Attach this code to the Form_Load procedure. This initializes the pizza size, crust, and eating location.
Private Sub Form_Load()
PizzaSize = "Small"
PizzaCrust = "Thin Crust"
PizzaWhere = "Eat In"
End Sub
6. Attach this code to the three option button array Click events. Note the use of the Index variable:
Private Sub optSize_Click(Index As Integer)
PizzaSize = optSize(Index).Caption
End Sub
Private Sub optCrust_Click(Index As Integer)
PizzaCrust = optCrust(Index).Caption
End Sub
Private Sub optWhere_Click(Index As Integer)
PizzaWhere = optWhere(Index).Caption
End Sub
7. Attach this code to the cmdBuild_Click event.
Private Sub cmdBuild_Click()
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
MsgBox Message, vbOKOnly, "Your Pizza"
End Sub
This code forms the first part of a message for a message box by integrating the pizza size, crust type, and eating location (vbCr is a symbolic constant representing a ‘carriage return’ that puts each piece of ordering information on a separate line). Next, the code cycles through the six topping check boxes and adds any checked information to the message. The code then displays the pizza order in a message box.
8. Attach this code to the cmdExit_Click event.
Private Sub cmdExit_Click()
End
End Sub
9. Run the application, the message box will be appeared.
เ
"Pizza Order" Application
SOURCE : www.kidwares.com
1. Start a new project. We'll build a form where a pizza order can be entered by simply clicking on check boxes and option buttons.
2. Draw three frames. In the first, draw three option buttons, in the second, draw two option buttons, and in the third, draw six check boxes. Draw two option buttons on the form. Add two command buttons. Make things look something like this.
3. Set the properties of the form and each control.
- Form1:
Caption Pizza Order
Name frmPizza
- Frame1:
- Frame2:
- Frame3
- Option1:
Name optSize
Value True
- Option2:
Name optSize (yes, create a control array)
- Option3:
Name optSize
- Option4:
Name optCrust
Value True
- Option5:
Name optCrust (yes, create a control array)
- Option6:
Name optWhere
Value True
- Option7:
Name optWhere (yes, create a control array)
- Check1:
Name chkTop
- Check2:
Name chkTop (yes, create a control array)
- Check3:
Name chkTop
- Check4:
Name chkTop
- Check5:
Name chkTop
- Check6:
Name chkTop
- Command1:
Name cmdBuild
- Command2:
Name cmdExit
4. Declare the following variables in the general declarations area:
Option Explicit
Dim PizzaSize As String
Dim PizzaCrust As String
Dim PizzaWhere As String
5. Attach this code to the Form_Load procedure. This initializes the pizza size, crust, and eating location.
Private Sub Form_Load()
PizzaSize = "Small"
PizzaCrust = "Thin Crust"
PizzaWhere = "Eat In"
End Sub
6. Attach this code to the three option button array Click events. Note the use of the Index variable:
Private Sub optSize_Click(Index As Integer)
PizzaSize = optSize(Index).Caption
End Sub
Private Sub optCrust_Click(Index As Integer)
PizzaCrust = optCrust(Index).Caption
End Sub
Private Sub optWhere_Click(Index As Integer)
PizzaWhere = optWhere(Index).Caption
End Sub
7. Attach this code to the cmdBuild_Click event.
Private Sub cmdBuild_Click()
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
MsgBox Message, vbOKOnly, "Your Pizza"
End Sub
This code forms the first part of a message for a message box by integrating the pizza size, crust type, and eating location (vbCr is a symbolic constant representing a ‘carriage return’ that puts each piece of ordering information on a separate line). Next, the code cycles through the six topping check boxes and adds any checked information to the message. The code then displays the pizza order in a message box.
8. Attach this code to the cmdExit_Click event.
Private Sub cmdExit_Click()
End
End Sub
9. Run the application, the message box will be appeared.
เ
The Application User Interface |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น