1 / 42

Objectives

Tutorial 20 – Shipping Hub Application Introducing Collections, the For Each … Next Statement and Access Keys.

creda
Download Presentation

Objectives

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 20 – ShippingHub ApplicationIntroducing Collections, the ForEach…Next Statement and Access Keys Outline20.1 Test-Driving the ShippingHub Application20.2 Package Class20.3 Using Properties TabIndex and TabStop20.4 Using Access Keys20.5 Collections20.6 ShippingHub Application: Using Class ArrayList20.7 ForEach…Next Repetition Statement20.8 Wrap-Up

  2. Objectives • In this tutorial, you will learn to: • Create and manipulate anArrayListobject. • Set theTabStopandTabIndexproperties of a control. • Create an access key for a control. • Use aFor Each…Nextloop to iterate through anArrayList.

  3. 20.1 Test-Driving the Shipping Hub Application

  4. 20.1 Test-Driving the Shipping Hub Application Figure 20.1 ShippingHub application when first run. • Run the Shipping Hubapplication • Debug > Start

  5. 20.1 Test-Driving the Shipping Hub Application Figure 20.2 Scanning a new package. • Click Scan NewButton • Click in Address:TextBox and type 318 Some Street

  6. Cursor now appears in the City:TextBox 20.1 Test-Driving the Shipping Hub Application Figure 20.3 Pressing the Tab key moves the cursor to the next TextBox.

  7. 20.1 Test-Driving the Shipping Hub Application Figure 20.4 Viewing all packages going to South Carolina. • You can view all Package ID’s by state using the ComboBox

  8. 20.2 Package Class

  9. Package class added to the ShippingHub project 20.2 Package Class Figure 20.6 SolutionExplorer with Package.vb added.

  10. 20.3 Using Properties TabIndexand TabStop • TabIndex and access keys • Requires only the keyboard (allows user to avoid constantly switching between using the mouse and keyboard).

  11. TabIndex box set to zero TabIndex boxes (not modified) 20.3 Using Properties TabIndexand TabStop Figure 20.7 Setting the TabIndex properties using the Tab Order view of the ShippingHub application. • Set TabStop property to True for controls that receive user input and False for the other controls

  12. 20.3 Using Properties TabIndexand TabStop Figure 20.8 TabOrder view of the ShippingHub application. • Set the TabIndex properties by clicking each control in the order indicated

  13. Access key letter underlined Using the & symbol to create an access key (there is no space between & and S) 20.4 Using Access Keys Figure 20.9 Creating an access key.

  14. 20.5 Collections • Collections • Used to store groups of related objects • Aid in storage and organization of data, requiring no knowledge of how they work. • ArrayList • Dynamic resizing capability • Grow and shrink according to storage needs • Contained in Collections namespace

  15. Action Control/Object Event , Label the application’s controls Application is run fraAddress , fraListByState , lblArrived , lblPackageID , , lblAddress lblCity , lblState lblZip FrmShippingHub Load Generate an initial package ID m_objRandom number Creat e an empty ArrayList m_objList btnNew Click Generate a unique package ID m_objRandom number , , Enable TextBoxes, the ComboBox btnAdd txtAddress , , txtCity cboState and the Add Button txtZip btnAdd Click , , Retrieve address, city, state and zip txtAddress txtCity , cboState txtZip code values; and disable input controls Add the package to the ArrayList m_objList Add the package number to the lstPackages ListBox Shipping Hub Figure 20.10 ACE table for the application. 20.6 Shipping Hub Application:Using Class ArrayList

  16. 20.6 Shipping Hub Application:Using Class ArrayList

  17. Declaring an ArrayList reference 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.11 Declaring the ArrayList reference. • Accessing ArrayList • Use the member-access operator (.) • OR • Import Collections using ImportsSystem.Collections

  18. Initializing the ArrayList reference 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.12 Creating an ArrayList object.

  19. Create a new Package object with a unique ID 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.13 Creating a package object.

  20. Displaying arrival time and package ID number in Labels 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.14 Displaying the package’s number and arrival time. • ToString method returns value representing object as a String • Example: 11/11/2002 9:34:00 AM

  21. Adding a Package object to an ArrayList 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.15 Adding a package to the ArrayList. • An Object’s position in ArrayList is called an index • – Index of first object is zero

  22. Removing the current package from the ArrayList 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.16 Removing a package from the ArrayList.

  23. Using code to change the text displayed on a Button 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.17 Changing the EditButton to display Update.

  24. Updating the ArrayList with new package information 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.18 Removing and inserting a package to update data.

  25. Using code to display the text on the Button 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.19 Setting the Button’s Text property back to Edit.

  26. Retrieving a Package object from an ArrayList 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.20 Retrieving a package from the ArrayList.

  27. Displaying data stored in the Package object 20.6 Shipping Hub Application:Using Class ArrayList Figure 20.21 Displaying the package data in the Form’s controls.

  28. 20.7 For Each…Next Repetition Statement Dim objPackage As PackageForEach objPackage In objArrayList lstPackages.Items.Add(objPackage.PackageNumber)Next • The ForEach…Next statement requires both a collection type and an element • Collection type: specifies the array or collection through which you wish to iterate • Element: Use to store a reference to a value in the collection type

  29. 20.7 For Each…Next Repetition Statement Figure 20.22 UML activity diagram for ForEach…Next repetition statement.

  30. Declaring the control variable for the ForEach…Next repetition statement 20.7 For Each…Next Repetition Statement Figure 20.23 Declaring a reference for use in ForEach…Next loop. • SelectedIndexChanged event raised when selected package in the ComboBox is changed

  31. ForEach…Next header 20.7 For Each…Next Repetition Statement Figure 20.24 Writing a ForEach…Next statement.

  32. Displaying package ID numbers only for packages destined for the specified state 20.7 For Each…Next Repetition Statement Figure 20.25 Displaying all packages going to selected state. • File > Save All • Debug > Start

  33. Initially, there are no objects in the ArrayList so set the position to zero Use a Random object to generate a random number for package IDs ShippingHub.vb(1 of 10)

  34. ShippingHub.vb(2 of 10)

  35. Display package ID numbers in ListBox if the state names match ShippingHub.vb(3 of 10)

  36. When the user clicks the < BACKButton, decrement the position. If the position was zero, set the position to the last object in the ArrayList 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 ShippingHub.vb(4 of 10)

  37. Set the position to the next package in the ArrayList ShippingHub.vb(5 of 10)

  38. ShippingHub.vb(6 of 10)

  39. Retrieve data from user, and store it in the Package object ShippingHub.vb(7 of 10)

  40. ShippingHub.vb(8 of 10)

  41. Enable or disable Buttons depending on value of blnState ShippingHub.vb(9 of 10)

  42. ShippingHub.vb(10 of 10)

More Related