120 likes | 271 Views
Arrays Part3. Objectives. Create and manipulate parallel one-dimensional arrays Create and initialize a two-dimensional array Store data in a two-dimensional array Search a two-dimensional array. Parallel One-Dimensional Arrays. Parallel arrays :
E N D
Objectives • Create and manipulate parallel one-dimensional arrays • Create and initialize a two-dimensional array • Store data in a two-dimensional array • Search a two-dimensional array
Parallel One-Dimensional Arrays • Parallel arrays: • Two or more arrays whose elements are related by their position in the arrays
Parallel One-Dimensional Arrays (continued) • Hands-on Example
Two-Dimensional Arrays • Two-dimensional array: • Resembles a table with rows and columns • Each element is identified by a unique combination of two subscripts: (row, column) • Subscripts are zero-relative
Two-dimensional array: • Syntax: Form 1 [Dim|Private] arrayname(highestrowsubscript, highestcolumnsububscript) as dataytype Form 2 [Dim|Private] arrayname(, ) as dataytype= {{ initial values}…….{initialvalues}}
Two-Dimensional Arrays (continued) • Hands-on Example
Two-Dimensional Arrays (continued) • Two-dimensional array: • Declared with highest row subscript and highest column subscript (zero-relative) • Number of rows = highest row subscript + 1 • Number of columns = highest column subscript + 1 • Can specify initial values for array elements • If no initial values are declared, array elements are automatically initialized
Storing Data in a Two-Dimensional Array • Hands-on Example
Searching a Two-Dimensional Array • Hands-on Example
Summary • Arrays: a group of related variables with the same name and same data type • Array element: one item in the array • One-dimensional array: each element is uniquely identified by its position (subscript) in the array • Two-dimensional array: each element is uniquely identified by its position (row and column subscripts) in the array • Subscripts are zero-relative
Summary (continued) • Number of elements in an array is the highest subscript value + 1 • For Each...Next statement: used to loop through all the elements in an array • Length property: returns the number of elements in an array • Array.Sort method: sorts the elements in a one-dimensional array in ascending order • Array.Reverse method: reverses the order of elements in a one-dimensional array