8.13. Changing the Size of an Array at Execution Time: Using the ReDim Statement

The number of elements in an array can be changed at execution time. For example, when an array is used to store information about all the employees in a company, the size of the array would change when the company hires a new employee or when an employee leaves the company. The ReDim statement enables you to dynamically change the array size, but not the type of the array elements, nor the number of dimensions in the array. Figure 8.21 demonstrates the ReDim statement.

Figure 8.21. Using ReDim statements to change the array size.
					1
					' Fig. 8.21: ReDimTest.vb
					2
					' Resize an array using the ReDim statement.
					3
					Module ReDimTest
 4
					Sub Main()
 5
					' create and initialize ...

Get Visual Basic 2005 for Programmers: Deitel Developer Series, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.