19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3. The two arrays in Example 3 are referred to as parallel arrays because subscripted<br />

variables having the same subscript are related.<br />

4. The integers m <strong>and</strong> n in the statement Dim arrayName(m To n) As varType can<br />

be positive, negative, or zero. The only restriction is that m cannot be greater<br />

than n. The same holds true for ReDim statements.<br />

5. Until a value is assigned to an element of an array, the element has its default<br />

value. Numeric variables have a default value of 0, <strong>and</strong> string variables have the<br />

default value “”, the empty string.<br />

6. The statement Dim arrayName(0 To n) As varType can be replaced by the statement<br />

Dim arrayName(n) As varType. The same holds for the ReDim statement.<br />

7. An array whose range has been specified by a ReDim statement is said to be<br />

dynamic. If array1() is a dynamic array, <strong>and</strong> array2() is another array of the<br />

same data type (such as String), then the line<br />

array1 = array2<br />

makes array1() an exact duplicate of array2(). It will have the same size <strong>and</strong><br />

contain the same information. This feature was added in <strong>Visual</strong> <strong>Basic</strong> 6.0.<br />

8. A dynamic array can be resized with another ReDim statement. However, the<br />

resized array loses all its information. If it is resized with the words ReDim<br />

Preserve, as much information as possible will be retained.<br />

6.2 USING ARRAYS<br />

This section considers three aspects of the use of arrays: processing ordered arrays, reading<br />

part of an array, <strong>and</strong> passing arrays to procedures.<br />

■ ORDERED ARRAYS<br />

An array is said to be ordered if its values are in either ascending or descending order. The<br />

following arrays illustrate the different types of ordered <strong>and</strong> unordered arrays. In an ascending<br />

ordered array, the value of each element is less than or equal to the value of the next element.<br />

That is,<br />

[each element] ≤ [next element].<br />

For string arrays, the ANSI table is used to evaluate the “less than or equal to” condition.<br />

Using Arrays 171

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!