1 / 17

Clearly Visual Basic: Programming with Visual Basic 2008

Clearly Visual Basic: Programming with Visual Basic 2008. Chapter 19 A Ray of Sunshine. Objectives. Explain the purpose of an array Create a one-dimensional array Store data in a one-dimensional array Sort the contents of a one-dimensional array Search a one-dimensional array.

beatty
Download Presentation

Clearly Visual Basic: Programming with Visual Basic 2008

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. Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine

  2. Objectives • Explain the purpose of an array • Create a one-dimensional array • Store data in a one-dimensional array • Sort the contents of a one-dimensional array • Search a one-dimensional array Clearly Visual Basic: Programming with Visual Basic 2008

  3. Let’s Join the Group • Simple variable (scalar variable) • One that is unrelated to any other variable in memory • Array of variables • Group of related variables • Each variable in an array • Has the same name and data type • Subscript • Unique number used to distinguish one variable in a one-dimensional array from another Clearly Visual Basic: Programming with Visual Basic 2008

  4. Clearly Visual Basic: Programming with Visual Basic 2008

  5. Clearly Visual Basic: Programming with Visual Basic 2008

  6. Clearly Visual Basic: Programming with Visual Basic 2008

  7. Let’s Join the Group (continued) • Elements in a numeric array • Initialized to the number 0 • Elements in a String array • Initialized to the empty string • Populating the array • Assigning initial values to an array Clearly Visual Basic: Programming with Visual Basic 2008

  8. Clearly Visual Basic: Programming with Visual Basic 2008

  9. My Friends Application • Will perform the following tasks: • Store four names in a one-dimensional String array named strFriends • Display the contents of the array in three label controls named: • lblOriginal, lblAscending, and lblDescending • To sort a one-dimensional array in descending order: • First, sort the values in ascending order; then use Array.Reversemethodto reverse array elements Clearly Visual Basic: Programming with Visual Basic 2008

  10. Salary Application • Will store six salary amounts in a one-dimensional Integer array named intSalaries • Each salary amount corresponds to a salary code • The valid codes are the numbers 1 through 6 • Figure 19-9 • Shows planning information for the application • Before accessing an array element: • Procedure should verify that the subscript is valid Clearly Visual Basic: Programming with Visual Basic 2008

  11. Clearly Visual Basic: Programming with Visual Basic 2008

  12. States Application • Stores the names of nine states in a one-dimensional String array named strStates • Names are stored in the order each was visited by the user • Interface provides a text box for the user to enter a state name • Figure 19-15 • Shows planning information for the application • Figure 19-16 • Shows Step Four of algorithm Clearly Visual Basic: Programming with Visual Basic 2008

  13. Clearly Visual Basic: Programming with Visual Basic 2008

  14. Clearly Visual Basic: Programming with Visual Basic 2008

  15. Summary • Variables in an array • Have the same name and data type • Each element in a one-dimensional array • Identified by a unique subscript that appears in parentheses after the array’s name • When declaring a one-dimensional array: • Provide either the highest subscript or the initial values Clearly Visual Basic: Programming with Visual Basic 2008

  16. Summary (continued) • Number of elements in a one-dimensional array • One number more than its highest subscript • Refer to an element in a one-dimensional array • Using the array’s name followed by the element’s subscript • You can use array variables just like any other variable Clearly Visual Basic: Programming with Visual Basic 2008

  17. Summary (continued) • One-dimensional array’s Length property • Contains an integer that represents the number of elements in the array • Array.Sort method • Sorts elements in a one-dimensional array in ascending order • Array.Reverse method • Reverses the order of the elements in a one-dimensional array Clearly Visual Basic: Programming with Visual Basic 2008

More Related