T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 20 Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next.

Slides:



Advertisements
Similar presentations
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.
Advertisements

Programming with Microsoft Visual Basic 2008 Fourth Edition
Programming with Microsoft Visual Basic th Edition
Microsoft Visual Basic: Reloaded Chapter Seven More on the Repetition Structure.
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Microsoft Visual Basic: Reloaded Chapter Six Repeating Program Instructions.
Excel and VBA Creating an Excel Application
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Getting Started Example ICS2O curriculum
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 9 Car Payment Calculator Application Introducing the Do While...Loop and Do Until...Loop.
Chapter 8: String Manipulation
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Flag Quiz Application Introducing One-Dimensional Arrays and ComboBox es.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Six Repeating Program Instructions.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Interest Calculator Application Introducing the For...Next Repetition Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 8 - Interest Calculator Application: Introducing.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhancing the Wage Calculator Application Introducing Function Procedures and.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Fund Raiser Application Introducing Scope, Pass-by-Reference and Option Strict.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Seven More on the Repetition Structure.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 27 - Phone Book Application Introducing Multimedia.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Ticket Information Application Introducing Sequential-Access Files.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 5 Completing the Inventory Application Introducing Programming.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 17 – Flag Quiz Application Introducing One-Dimensional.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
Tutorial 6 The Repetition Structure
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Six The Do Loop and List Boxes.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 19.1 Test-Driving the Shipping Hub Application.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Security Panel Application Introducing the Select Case Multiple-Selection Statement.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Screen Scraping Application Introducing String Processing.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Class Average Application Introducing the Do...Loop While and Do...Loop Until.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Microwave Oven Application Building Your Own Classes and Objects.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Shipping Hub Application.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
INSERT BOOK COVER 1Copyright © 2012 Pearson Education, Inc. Publishing as Prentice Hall. Exploring Getting Started with VBA for Microsoft Office 2010 by.
1.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Bookstore Application: Middle Tier Introducing Code-Behind Files, Session State.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 5A Repetition (Concepts)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 18 – Student Grades Application Introducing.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Inventory Application.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code that may be executed several times. Fixed-count (definite) loops repeat a fixed.
Unit 6 Repetition Processing Instructor: Brent Presley.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
Iterations (aka Loops). 2 Loops Loops (iterations) are segments of code (loop body) that may be executed several times. Fixed-count (definite) loops repeat.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 11.1 Test-Driving the Interest Calculator Application 11.2 Essentials of Counter-Controlled Repetition.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
14 Shipping Time App Using Dates and Timers
Visual Basic 2010 How to Program
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 3: Introduction to Problem Solving and Control Statements
CIS 16 Application Development Programming with Visual Basic
Presentation transcript:

T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Shipping Hub Application Introducing Generic Collections, LINQ, For Each...Next and Access Keys

 2009 Pearson Education, Inc. All rights reserved. 2 Outline 20.1 Test-Driving the Shipping Hub Application 20.2 Package Class 20.3 Using Properties TabIndex and TabStop 20.4 Using Access Keys 20.5 Collections

 2009 Pearson Education, Inc. All rights reserved. 3 Outline 20.6 Shipping Hub Application: Using Class List ( Of T ) 20.7 For Each...Next Repetition Statement 20.8 Language-Integrated Query (LINQ)

 2009 Pearson Education, Inc. All rights reserved. 4 In this tutorial you will learn: ■Use generic collections. ■Create and manipulate a List(Of T) object. ■Use Language Integrated Query (LINQ) to select elements from a collection. ■Set the MaxLength property of a TextBox. Objectives

 2009 Pearson Education, Inc. All rights reserved. 5 In this tutorial you will learn: ■Specify the tab order in a GUI using the TabStop and TabIndex properties of the controls. ■Create an access key for a control. ■Use a For Each...Next loop to iterate through a collection. ■Obtain a String representation of an object. Objectives

Application Requirements  2009 Pearson Education, Inc. All rights reserved Test-Driving the Shipping Hub Application A shipping company receives packages at its headquarters, which functions as its shipping hub. After receiving the packages, the company ships them to one of the following states: Alabama, Florida, Georgia, Kentucky, Mississippi, North Carolina, South Carolina, Tennessee, West Virginia or Virginia. The company needs an application to track the packages that pass through its shipping hub. For each package that arrives at the hub, the user clicks the application’s Scan New Button, to generate a package ID number. Once a package has been scanned, the user should be able to enter the shipping address for it. The user should be able to navigate through the list of scanned packages by using Button s and by viewing a list of all packages destined for a particular state.

 2009 Pearson Education, Inc. All rights reserved. 7 Test-Driving the Shipping Hub Application ■Run the completed application (Fig. 20.1). Figure 20.1 | Shipping Hub application when first run.

 2009 Pearson Education, Inc. All rights reserved. 8 Test-Driving the Shipping Hub Application (Cont.) ■Click the Scan New Button. ■The application displays a package ID number and the arrival time, enables the TextBox es and allows the user to enter the package information (Fig. 20.2). Figure 20.2 | Scanning a new package.

 2009 Pearson Education, Inc. All rights reserved. 9 ■Type 318 Some Street in the Address: TextBox, then press the Tab key. Note that the cursor moves to the City: TextBox (Fig. 20.3). ■Fill in other input values, then click the Add Button to add the package to the application’s List. Test-Driving the Shipping Hub Application (Cont.) Figure 20.3 | Pressing the Tab key moves the cursor to the next TextBox. Cursor now appears in the City: TextBox

 2009 Pearson Education, Inc. All rights reserved. 10 GUI Design Tip Using the Tab key is an efficient way for users to navigate through the controls in a GUI.

 2009 Pearson Education, Inc. All rights reserved. 11 ■The application’s NEXT > and < BACK Button s allow the user to navigate the list of packages. ■The user can click on the Remove Button to delete packages and on the Edit Button to update a particular package’s information. ■The ComboBox on the right side of the application allows the user to select a state. –When a state is selected, all of the package ID numbers of packages destined for that state are displayed in the ListBox (Fig. 20.4). Test-Driving the Shipping Hub Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 12 Figure 20.4 | Viewing all packages going to South Carolina. Test-Driving the Shipping Hub Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 13 ■The table in Fig describes the properties for class Package. Figure 20.5 | Properties of class Package Package Class

 2009 Pearson Education, Inc. All rights reserved. 14 ■Open the template application. ■In the Solution Explorer, right click the ShippingHub project. –Select Add > Existing Item.... –When the Add Existing Item dialog appears, select the Package.vb file and click Add (Fig 20.6). Adding a Class to an Application Figure 20.6 | Solution Explorer with Package.vb added. Package class added to the ShippingHub project

 2009 Pearson Education, Inc. All rights reserved. 15 ■It is awkward for users to have to select each TextBox. ■Most applications allow the user to press the Tab key to navigate between the controls on the Form. ■The TabIndex property allows you to specify the order in which focus transfers between controls. –Some controls, such as a read-only TextBox, should not be selected using the Tab key. –The TabStop property specifies whether the user can select the control using the Tab key Using Properties TabIndex and TabStop

 2009 Pearson Education, Inc. All rights reserved. 16 ■The TabStop property defaults to True for controls that receive user input. ■The IDE provides a view called Tab Order. –Select the Form, then select View > Tab Order (Fig. 20.7). Setting Properties TabIndex and TabStop Figure 20.7 | Setting the TabIndex properties using the Tab Order view of the Shipping Hub application. TabIndex box set to zero TabIndex boxes (not modified)

 2009 Pearson Education, Inc. All rights reserved. 17 ■Click the Package Information GroupBox, and note that its value becomes 0. Then click the Address : TextBox. –Now the value changes to 0.0. The first zero refers to the TabIndex of the container, and the second zero refers to the TabIndex for that control within the container. Setting Properties TabIndex and TabStop (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 18 GUI Design Tip Use the TabIndex property to define the logical order in which the user should enter data. Usually the order transfers the focus of the application from top to bottom and left to right.

 2009 Pearson Education, Inc. All rights reserved. 19 ■Continue setting the TabIndex properties by clicking the Scan New Button. Then click the remaining unchanged controls in the order indicated in Fig ■Exit the Tab Order view by selecting View > Tab Order or by pressing the Esc key. Figure 20.8 | Tab Order view of the Shipping Hub application. Setting Properties TabIndex and TabStop (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 20 ■Access keys (or keyboard shortcuts) allow the user to perform an action on a control using the keyboard. –Insert an & symbol in the control’s Text property before the letter you wish to use as an access key. ■To display an ampersand character on a control, type && Using Access Keys

 2009 Pearson Education, Inc. All rights reserved. 21 ■Insert an & symbol before the letter S in the Text property of the Scan New Button (Fig. 20.9). ■If the user presses Alt, then S, this has the same effect as “clicking” the Scan New Button. ■Create access keys for the remaining Button s. ■The access key does not have to be the first letter. Figure 20.9 | Creating an access key. Creating Access Keys Using the & symbol to create an access key (there is no space between & and S) Access key letters underlined (may need to press the Alt key first)

 2009 Pearson Education, Inc. All rights reserved. 22 GUI Design Tip Use access keys to allow users to “click” a control using the keyboard.

 2009 Pearson Education, Inc. All rights reserved. 23 ■The.NET Framework Class Library provides several collections. –These classes provide methods that facilitate the storage and organization of your data. –Collections simplify the details of how the objects are being stored. ■ List(Of T) provides a convenient alternative to arrays. –The identifier T is a placeholder which you replace with an actual type. Dim list As List(Of Integer) Dim list2 As List(Of Package) –Dynamic resizing enables the List object to change its size Collections

 2009 Pearson Education, Inc. All rights reserved. 24 Software Design Tip Use a List to store a group of values when the number of elements in the group varies during the running of an application.

 2009 Pearson Education, Inc. All rights reserved. 25 When the Form loads: Generate a random initial package ID number and arrival time Set the SelectedIndex of the State ComboBox to 0 Create an empty List of Packages When the user clicks the Scan New Button: Generate the next package ID number Create a new Package object Display the new Package’s package number and arrival time Enable the TextBoxes, the ComboBox and the Add Button 20.6 Shipping Hub Application: Using Class List(Of T)

 2009 Pearson Education, Inc. All rights reserved. 26 When the user clicks the Add Button: Retrieve address, city, state and zip code values; and disable input controls Add the package to the List Enable the Package Information GroupBox and the appropriate Buttons Disable the Add Button Add the package number to the ListBox Change the Packages by Destination ComboBox value to the package’s destination state Enable the New Button 20.6 Shipping Hub Application: Using Class List(Of T) (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 27 When the user clicks the < BACK Button: Display the previous package in the List When the user clicks the NEXT > Button: Display the next package in the List When the user clicks the Remove Button: Remove the package from the Packages by Destination ListBox Remove the package from the List 20.6 Shipping Hub Application: Using Class List(Of T) (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 28 When the user clicks the Edit Button: Change the Button to read Update Allow the user to modify package address information When the user clicks the Update Button: Update the package’s information in the List Disable controls that allow user input, and change the Update Button to read Edit When the user chooses a different state in the Packages by Destination ComboBox: Display the package number for each package destined for that state in the ListBox 20.6 Shipping Hub Application: Using Class List(Of T) (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 29 ■Use an ACE table to convert the pseudocode to Visual Basic (Fig ). Figure | ACE table for the Shipping Hub application. (Part 1 of 5.) Action/Control/Event (ACE) Table for the Shipping Hub Application

 2009 Pearson Education, Inc. All rights reserved. 30 Figure | ACE table for the Shipping Hub application. (Part 2 of 5.) Action/Control/Event (ACE) Table for the Shipping Hub Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 31 Figure | ACE table for the Shipping Hub application. (Part 3 of 5.) Action/Control/Event (ACE) Table for the Shipping Hub Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 32 Figure | ACE table for the Shipping Hub application. (Part 4 of 5.) Action/Control/Event (ACE) Table for the Shipping Hub Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 33 Figure | ACE table for the Shipping Hub application. (Part 5 of 5.) Action/Control/Event (ACE) Table for the Shipping Hub Application (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 34 ■Declare a List(Of Package) list (Fig ). Figure | Declaring the List(Of Package) reference. Creating a List of Packages Declaring a List(Of Package) reference

 2009 Pearson Education, Inc. All rights reserved. 35 ■Assign the reference of a new List(Of Package) to the instance variable list (Fig ). Figure | Creating a List(Of Package) object. Creating a List of Packages (Cont.) Initializing the List(Of Package) reference

 2009 Pearson Education, Inc. All rights reserved. 36 ■The user clicks the Scan New Button when a new package arrives at the shipping hub. ■Line 28 (Fig ) increments packageID to ensure that all packages have a unique identification number. Figure | Creating a Package object. Adding and Removing Packages Create a new Package object with a unique ID

 2009 Pearson Education, Inc. All rights reserved. 37 ■The application should display a scanned package’s arrival time and package number (Fig ). ■The ToString method returns a String representation of an object. – Date ’s ToString method returns the date as a String. –For some.NET classes, ToString merely returns the class name. Adding and Removing Packages (Cont.) Displaying arrival time and package ID number in Labels Figure | Displaying the package’s number and arrival time.

 2009 Pearson Education, Inc. All rights reserved. 38 ■This code (Fig ) stores the package information by adding the Package object to list using the List ’s Add method. ■New Package s are added to the end of the List. Figure | Adding a package to the List. Adding a Package object to a List Adding and Removing Packages (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 39 ■An element’s location in the List is the element’s index. ■The List class provides a simple way to remove elements from the List. –The RemoveAt method removes a package from the List (Fig ). –The argument passed to the method RemoveAt is the index of the Package in the List. Adding and Removing Packages (Cont.) Removing the current Package from the List Figure | Removing a Package from the List.

 2009 Pearson Education, Inc. All rights reserved. 40 ■If a Package at index 3 is removed from the List, the Package that was previously at index 4 will then be located at index 3. ■The Count property returns the number of elements currently stored in the List. Adding and Removing Packages (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 41 ■When the Edit Button is clicked, line 135 (Fig ) changes the text on the Edit Button to &Update. ■This indicates that the user should click the same Button to submit changes to the package information. Figure | Changing the Edit Button to display Update. Using code to change the text displayed on a Button Updating Package Information

 2009 Pearson Education, Inc. All rights reserved. 42 ■When the user chooses to alter the package information, the Package is removed from the List and a new one with the updated address information is added (Fig ). Figure | Removing and inserting a Package to update data. Updating the List with new package information Updating Package Information (Cont.) ■The Insert method allows you to specify the index in the List at which to insert the Package.

 2009 Pearson Education, Inc. All rights reserved. 43 ■After the user clicks the Update Button, the TextBox es are disabled, and the text on the Update Button is reset to Edit (Fig ). Figure | Setting the Button ’s Text property back to Edit. Using code to display the text on the Button Updating Package Information (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 44 ■Retrieve the data from the List using the elements index enclosed in parentheses (Fig ). Figure | Retrieving a Package from the List. Retrieving a Package object from a List Displaying a Package

 2009 Pearson Education, Inc. All rights reserved. 45 ■These lines retrieve the package information from packageObject and display the data in the corresponding controls on the Form (Fig ). Figure | Displaying the package data in the Form ’s controls. Displaying data stored in the Package object Displaying a Package (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 46 ■The For Each...Next repetition statement iterates through all the elements in an array or a collection. ■The statement uses a control variable that can be assigned each element in the collection: For Each packageObject As Package In list packagesListBox.Items.Add(packageObject. PackageNumber) Next 20.7 For Each...Next Repetition Statement

 2009 Pearson Education, Inc. All rights reserved. 47 ■The statement requires both a group and an element. –The group specifies the collection through which you wish to iterate. –The element is used to store a reference to an object in the group. –The statement assigns the current element in the collection to the element variable For Each...Next Repetition Statement (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 48 Good Programming Practice Use a For Each...Next repetition statement to iterate through values in an array or collection without using a counter variable.

 2009 Pearson Education, Inc. All rights reserved. 49 Common Programming Error If the element in a For Each...Next statement cannot be converted to the same type as the groups’s objects, a compilation error occurs. For example, if a List contained Date values, declaring a reference to a Package object as the element would cause a compilation error.

 2009 Pearson Education, Inc. All rights reserved. 50 ■Figure shows the UML activity diagram for the For Each...Next statement. Figure | UML activity diagram for For Each...Next repetition statement For Each...Next Repetition Statement (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 51 ■This loop (Fig ) iterates through list. ■This code is added to a ComboBox ’s SelectedIndexChanged event handler. –The SelectedIndexChanged event occurs when the value selected in the ComboBox changes. Inserting a For Each...Next Statement For Each...Next header Figure | Writing a For Each...Next statement.

 2009 Pearson Education, Inc. All rights reserved. 52 ■These lines contain an If...Then statement (Fig ) that tests each package’s destination state against the state name displayed in the Packages by Destination ComboBox. Figure | Displaying all packages going to selected state. Inserting a For Each...Next Statement (Cont.) Displaying package ID numbers only for packages destined for the specified state

 2009 Pearson Education, Inc. All rights reserved. 53 ■Visual Basic 2008 and the.NET 3.5 framework introduce Language-Integrated Query (LINQ). –A query retrieves specific information from a data source, such as a collection. ■A typical LINQ query contains three clauses: –The From clause specifies a range variable and the data source to query. –The Where clause specifies the conditions that must be met for the item to be included in the results. –The Select clause specifies the value(s) placed in the results Language-Integrated Query (LINQ)

 2009 Pearson Education, Inc. All rights reserved. 54 ■The following LINQ to Objects query selects all the Package s in list that are destined for Boston: Dim cityQuery = From p In list _ Where p.City = "Boston" _ Select p ■If the expression in the Where clause evaluates to True, the Select clause includes the corresponding Package in the result. ■LINQ uses deferred execution—the query does not execute until you attempt to iterate through the query results Language-Integrated Query (LINQ) (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 55 ■Lines 222–225 of Figure declare a LINQ query that selects from list all the Package s destined for the specified state. Figure | Declaring a LINQ query. Using LINQ to Select Package s from a List Declaring a LINQ query to select Packages destined for specified state

 2009 Pearson Education, Inc. All rights reserved. 56 ■The query results are contained in an IEnumerable(Of Package) object. – IEnumerable is an interface—a set of methods that can be called on an object to tell the object to perform some task or return some piece of information. –You can call any IEnumerable method on an array or collection object to iterate through its elements. Using LINQ to Select Package s from a List (Cont.)

 2009 Pearson Education, Inc. All rights reserved. 57 Figure | Iterating through query results using a For Each...Next statement. Use a For Each...Next statement to display the results of the query Using LINQ to Select Package s from a List (Cont.) ■Replace the previous Package-selection code with lines of Fig

 2009 Pearson Education, Inc. All rights reserved. 58 ■Figure presents the source code for the Shipping Hub application. Outline (1 of 12 ) Declares a List to be used to store packages Initially, there are no objects in the List, so set the position to zero Use a Random object to generate a random number for package IDs Create a List object

 2009 Pearson Education, Inc. All rights reserved. 59 Outline (2 of 12 ) Use ToString to convert values

 2009 Pearson Education, Inc. All rights reserved. 60 Outline (3 of 12 )

 2009 Pearson Education, Inc. All rights reserved. 61 Outline (4 of 12 ) When the user clicks the < BACK Button, decrement the position. If the position was zero, set the position to the last object in the List

 2009 Pearson Education, Inc. All rights reserved. 62 Outline (5 of 12 ) When the user clicks the NEXT > Button, increment the position. If the position was the last object in the array, set the position to zero

 2009 Pearson Education, Inc. All rights reserved. 63 Outline (6 of 12 ) Set the position to the next package in the List

 2009 Pearson Education, Inc. All rights reserved. 64 Outline (7 of 12 ) Using & in the Text property of a Button to create an access key Removing and inserting items from/into a List

 2009 Pearson Education, Inc. All rights reserved. 65 Outline (8 of 12 ) Using & in the Text property of a Button to create an access key Retrieve data from user, and store it in the Package object

 2009 Pearson Education, Inc. All rights reserved. 66 Outline (9 of 12 ) Using ToString to convert values

 2009 Pearson Education, Inc. All rights reserved. 67 Outline (10 of 12 ) Enable or disable Button s depending on value of state

 2009 Pearson Education, Inc. All rights reserved. 68 Outline (11 of 12 )

 2009 Pearson Education, Inc. All rights reserved. 69 Outline (12 of 12 ) Declare a LINQ query to select Packages destined for specified state