Looping and Multiple Forms - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

Looping and Multiple Forms

Description:

Click the Icon property ellipsis button. Select the CHECKMRK file from the ... Click the Columns property ellipsis button in the ListView Control Properties window ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 51
Provided by: steve1751
Category:

less

Transcript and Presenter's Notes

Title: Looping and Multiple Forms


1
Chapter 6
  • Looping andMultiple Forms

2
Objectives
  • 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

3
Objectives
  • 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

4
Objectives
  • 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)
7
Creating 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

8
Creating 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)
11
Changing 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

12
Changing 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

13
Anchoring 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

14
Changing 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

15
Adding 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

16
Creating 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

17
CheckBox Control Properties
18
Declaring an Object Using an Object Variable
19
Declaring an Object and Showing a Form
  • Enter the code below, beginning on line 119

20
Looping and the Do Statement
21
The Do While and Do Until Statements
22
The WhileEnd While Statement
23
Implementing a Loop Using a Do Until Statement
  • Enter the following code, starting on line 136

24
Working with Collections in ListView Controls
  • Group of one or more objects that can be accessed
    and operated on as a single entity

25
Adding Items to a ListView Control
  • Text Property
  • SubItems Property

26
Adding Items to a ListView Control
  • Enter the following code, starting on line 137

27
ForNext Statement
  • Great for counter-controlled loops
  • More efficient than a Do While Loop
  • Easier to read
  • Uses less memory
  • Faster execution

28
The 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

29
The 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

30
Exiting a Loop Prematurely The Exit Statement
31
Nested ForNext Loops
32
Implementing a Loop Using a ForNext Statement
33
Implementing a Loop Using a ForNext Statement
  • Enter the following code, starting on line 150

34
The For EachNext Statement
35
Coding 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

36
String Manipulation
37
Concatenation Operators
38
Coding a Concatenation Operator
  • Enter the code below, starting on line 164

39
Removing 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

40
Keyboard 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

41
Coding 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

42
The 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)
44
Setting 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
  • Click the OK button

46
Finish 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

47
Summary
  • 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

48
Summary
  • 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

49
Summary
  • Code a keyboard event
  • Code a form Resize event procedure
  • Work with multiple code windows
  • Specify a Startup object for a project

50
Chapter 6 Complete
Write a Comment
User Comments (0)
About PowerShow.com