You are on page 1of 2

Chapter 8 Homework Solutions:

Chapter 8-Arrays ANSWERS TO REVIEW QUESTIONS 1. Define the following terms: Array: An array is a series of individual variables, all referenced by the same name. (Sometimes arrays are referred to as tables or subscripted variables.) Element: The individual variables in an array are referred to as elements. Subscript: The subscript (inside the parentheses) is the position of the element within the array. (The subscript may also be called an index.) Control array: A control array is a group of controls sharing the same name. Each of the controls in an array must be the same class. An advantage of using a control array, rather than independent controls, is that the controls share one Click event. Subscripted variable: A subscripted variable is an element of an array. Describe the logic of a table lookup. A table lookup is used to search a table or an array to find a value when the subscript is not directly known. A Do/Loop or a For / Next statement is used to step through the table, comparing the lookup value to one item in the list, then the next, and the next, until a match is found. It isn't necessary to arrange the fields being searched in any particular sequence. Name some situations in which it is important to perform validation when working with subscripted variables. When working with subscripted variables, it is possible to reference an element that does not exist, thus causing a Subscript Out of Range error. It is important to perform validation to determine that the element is within the range of acceptable values. This is particularly important when data input will be from a text box. When performing a table lookup, it is possible that the user could enter a value that will not match any value in the table. This situation would result in an error. In this case, a message box should be displayed to the user. Why would a list box control need both a ListIndex property and an ItemData property? The ListIndex indicates the position of each element in an array. If the list is sorted, the ListIndex will not necessarily be the same as it was when the list was created. The ListIndex of a sorted list indicates an items current position in the array after the sort. The ItemData property is used to associate a specific number with each item in the list. Each element of the List property can have a corresponding ItemData that doesn't change when the list is sorted. Compare a two-dimensional table to an array of a user defined data type. Two-dimensional tables have horizontal rows and vertical columns. When referring to individual elements of the table, two subscripts must always be used. Each field of data within a user-defined type is referred to as an element of the data type. To access the elements use the dot notation, Variable.Element. Arrays of a user defined data type must use the index to reference the position of the element in the data type. You can specify indexes in both two-dimensional tables and arrays of a user defined data type in order to access an individual element or cell. Two-dimensional tables and arrays of

2.

3.

4.

5.

a user defined data type allow the user to change the contents of each cell in code. All of the values of the variables remain memory. 6. When initializing values in a two-dimensional table, what statements should be used? Although numeric array elements are initially set to zero and string elements are set to empty strings, many situations require that you initialize arrays to zero or some other value. You can use nested For/Next loops or For Each/Next to set each array element to an initial value. An assignment statement in the inner loop will be executed in order to initialize the values in the table.

You might also like