Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine.

Similar presentations


Presentation on theme: "Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine."— Presentation transcript:

1 Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine

2 Clearly Visual Basic: Programming with Visual Basic 2008 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 2

3 Clearly Visual Basic: Programming with Visual Basic 2008 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 3

4 Clearly Visual Basic: Programming with Visual Basic 20084

5 5

6 6

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 7

8 Clearly Visual Basic: Programming with Visual Basic 20088

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.Reverse method to reverse array elements 9

10 Clearly Visual Basic: Programming with Visual Basic 2008 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 10

11 Clearly Visual Basic: Programming with Visual Basic 200811

12 Clearly Visual Basic: Programming with Visual Basic 2008 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 12

13 Clearly Visual Basic: Programming with Visual Basic 200813

14 Clearly Visual Basic: Programming with Visual Basic 200814

15 Clearly Visual Basic: Programming with Visual Basic 2008 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 15

16 Clearly Visual Basic: Programming with Visual Basic 2008 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 16

17 Clearly Visual Basic: Programming with Visual Basic 2008 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 17


Download ppt "Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 19 A Ray of Sunshine."

Similar presentations


Ads by Google