Ppt lesson 12

1,420 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,420
On SlideShare
0
From Embeds
0
Number of Embeds
53
Actions
Shares
0
Downloads
34
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Ppt lesson 12

  1. 1. Microsoft Visual Basic 2005 BASICS Lesson 12 Arrays
  2. 2. Objectives Declare an array. Enter information into an array. Access the information in an array. Use loops with arrays. Use parallel arrays.
  3. 3. Declaring and Accessing Arrays Arrays Allow you to gather and manipulate different pieces of information of the same type
  4. 4. Declaring a Variable Declaring variables to manage a set of values This approach works, but is not very convenient or flexible.
  5. 5. Difficulties with Using Variables Difficulties Entering values is very tedious. It is very easy to make a mistake. Solutions do not scale well. Solution Use arrays instead.
  6. 6. Declaring Arrays An array allows you to refer to a series of variables by the same name and to use an index, or subscript, to tell them apart. Visual Basic arrays are zero-based. The size of the array must be declared. An array can be declared with an initialization list.
  7. 7. Entering and Accessing the Elements in an Array Index (or subscript) Identifies the element to process Can be specified using a variable or an equation Must be a value between zero and the upper bound
  8. 8. Entering and Accessing the Elements in an Array (cont.)
  9. 9. Making an Array User-Friendly Important to trap errors with arrays Verify index values before using them Zero-based array does not always fit Programmer can hide the way information is stored Allow users to enter values in the way they think of the data (i.e., not zero-based) Have the program add or subtract numbers to correctly index into the array
  10. 10. Making an Array User-Friendly (cont.)
  11. 11. Array Methods and Properties Length property Returns the number of elements in an array GetLowerBound and GetUpperBound methods Return integers representing the lower and upper bounds of an array
  12. 12. Using Loops with Arrays Common ways that arrays and loops are used together A loop can be used to apply the same process to each element in an array. A loop can be used to prompt for input for each element in an array and set its value. An array can be searched by using an If statement in a loop that compares each element of the array with a specific value.
  13. 13. Using Loops with Arrays (cont.)
  14. 14. Parallel Arrays Parallel arrays Arrays of the same length Each element in one array is logically related to an element in the second array with the same index value
  15. 15. Parallel Arrays (cont.)
  16. 16. Summary Visual Studio 2005 supports arrays that use an index or subscript to access different variables with the same name. All elements of an array are of the same data type. Arrays are declared by specifying the upper bound of the array.
  17. 17. Summary (cont.) Arrays can be declared using initialization lists that set the starting values of the array. When arrays are declared using initialization lists, the upper bound is calculated by the system based on the number of items in the list. Individual elements in an array are read or changed by using an index value in parentheses to identify the element to use.
  18. 18. Summary (cont.) The GetLowerBound and GetUpperBound methods can be used to check that an index value is in the allowable range. The Length method of an array returns the number of elements in an array. Arrays can be processed sequentially using a loop.
  19. 19. Summary (cont.) Parallel arrays are any number of arrays, which may be of different data types, that hold information in corresponding elements.

×