Title: Looping and Multiple Forms
1Chapter 6
- Looping andMultiple Forms
2Objectives
- Add additional forms to a project
- Change the default icon on the title bar of a
form - Use the ListView controls to display a list of
items on a form - Use the CheckBox controls in an application
- Use the Anchor property of controls
3Objectives
- Work with Collections in code
- Code a Do Until loop
- Code a Do While loop
- Code a ForNext and a For EachNext loop
- Code a concatenation operator
4Objectives
- Code a keyboard event
- Code a form Resize event procedure
- Work with multiple code windows
- Specify a Startup object for a project
5(No Transcript)
6(No Transcript)
7Creating the User Interface
- Open a New Project named Todays Sales Check in
the Chapter6 folder on your Data Disk - Set the following properties for your form
8Creating the User Interface
- Add a ListView control and three Button controls
to your form - Select the Icon property in the Properties window
- Click the Icon property ellipsis button.
- Select the CHECKMRK file from the C\Program
Files\Microsoft Visual Studio .NET\Common7\Graphic
s\Icons\Misc folder - Click the Open button
9(No Transcript)
10(No Transcript)
11Changing the Properties of a ListView Control
- Click the Columns property ellipsis button in the
ListView Control Properties window - Click the Add button
- Select the Text property value for the
ColumnHeader1 member. Type Item Description as
the property value. Select the Width property
value for the ColumnHeader1 member. Type 190 as
the property value and click the Add button
12Changing the Properties of a ListView Control
- Select the Text property value for the
ColumnHeader2 member and type Total Sales as the
property value. - Select the Width property value for the
ColumnHeader1 member and type 79 as the property
value. - Click the Add button.
- When the ColumnHeader3 member is added, select
the Text property value for the ColumnHeader3
member. Type On Sale as the property value and
click OK
13Anchoring Controls
- Select the three button controls on the form, by
holding CTRL while clicking each button - Click the button anchor indicator to select it.
Click the left and top anchor indicators to
deselect them and press ENTER - Select lstTodaysSales and click the down arrow in
the Anchor property of the Properties window - Click the bottom and right anchors to select
them, and press ENTER
14Changing the File Name of a Form
- Right-click the Form1.vb form in the Solution
Explorer window - Click the Rename command on the shortcut menu.
Type Todays Sales Check Form.vb and press ENTER
15Adding a Form to a Project and Creating the
Interface
- Right-click the Todays Sales Check project in
the Solution Explorer window and then point to
Add on the shortcut menu - Click the Add Windows Form command on the Add
submenu and select Form1 in the Name text box and
then type Add Item Form - Click the Open button
16Creating an Interface on a Newly Added Form
- Add two Label controls, one TextBox control, one
NumericUpDown control, a CheckBox control, and a
button control - Set the form, label, text box, and
NumericUpDowncontrol properties as specified on
pages VB 6.31 and VB 6.32
17CheckBox Control Properties
18Declaring an Object Using an Object Variable
19Declaring an Object and Showing a Form
- Enter the code below, beginning on line 119
20Looping and the Do Statement
21The Do While and Do Until Statements
22The WhileEnd While Statement
23Implementing a Loop Using a Do Until Statement
- Enter the following code, starting on line 136
24Working with Collections in ListView Controls
- Group of one or more objects that can be accessed
and operated on as a single entity
25Adding Items to a ListView Control
- Text Property
- SubItems Property
26Adding Items to a ListView Control
- Enter the following code, starting on line 137
27ForNext Statement
- Great for counter-controlled loops
- More efficient than a Do While Loop
- Easier to read
- Uses less memory
- Faster execution
28The Execution of a ForNext Loop
- The first time the loop executes, intNumber is
initialized at 1 - intNumber is compared with 100. Because it is
less than or equal to 100, the statements in the
For loop are executed - Control returns to the For statement, where the
value of intCount is incremented by 1
29The Execution of a ForNext Loop
- If the value of intCount is less than or equal to
100, execution of the ForNext loop continues - When the value of intCount is greater than 100,
control transfers to the statement following the
corresponding Next statement
30Exiting a Loop Prematurely The Exit Statement
31Nested ForNext Loops
32Implementing a Loop Using a ForNext Statement
33Implementing a Loop Using a ForNext Statement
- Enter the following code, starting on line 150
34The For EachNext Statement
35Coding the String Replace() Method
- Click line 163 and enter the code below
- This code replaces the dollar sign in the
strItemSales variable with a 0, so that the
string can be converted to a number and used in
an expression
36String Manipulation
37Concatenation Operators
38Coding a Concatenation Operator
- Enter the code below, starting on line 164
39Removing Items from a ListView Control
- Click the Todays Sales Form.vbDesign tab in the
main work area. Double-click the btnClearList
button. When the code window appears, click line
181 and then enter the code below
40Keyboard Events
- Click the Object box arrow in the code window
- Click lstTodaysSales in the Object list. Click
the Procedure box arrow in the code window.
Select KeyDown in the Procedures list - Enter the code below, starting on line 185
41Coding a Form Resize Event
- Click the Object box arrow in the code window
- Click Base Class Events in the Object list.
Click the Procedures box arrow in the Procedures
box in the code window. Select Resize in the
Procedures list - Enter the below lines of code, starting on line
191
42The Me Keyword and Coding a Second Form
- Click the Add Item Form.vbDesign tab in the
main work area. Double-click the btnOK button.
Enter Option Strict On as the first line of code
in the form - Enter lines 120 through 127 of the code on the
following slide - Click the Add Item Form.vbDesign tab in the
main work area. Double-click any blank area on
the form. Type lines 131 through 136 of code in
the frmAddItem_Load event procedure
43(No Transcript)
44Setting the Startup Object for a Project
- Click the Todays Sales Check project in the
Solution Explorer window and then click the
Property Page button in the Properties window - Click the Startupobject box arrow. Select
frmTodaySalesCheck in the list
45 46Finish the Project
- Click the Save All button on the Standard toolbar
- Test your project with the test data on page VB
6.79 - Print your programs documentation
- Quit Visual Basic .NET
47Summary
- Add additional forms to a project
- Change the default icon on the title bar of a
form - Use the ListView controls to display a list of
items on a form - Use the CheckBox controls in an application
- Use the Anchor property of controls
48Summary
- Work with Collections in code
- Code a Do Until loop
- Code a Do While loop
- Code a ForNext and a For EachNext loop
- Code a concatenation operator
49Summary
- Code a keyboard event
- Code a form Resize event procedure
- Work with multiple code windows
- Specify a Startup object for a project
50Chapter 6 Complete