Chapter 11 Using Arrays to Manage Numeric and String Data 283
- Click the Start Debugging button on the Standard toolbar to run the program.
- Click the Enter Temps button, and when prompted by the InputBox function, enter seven
different temperatures. (How about using the temperatures from your last vacation?)
The InputBox function dialog box looks like this: - After you’ve entered the temperatures, click the Display Temps button.
Using the array, Visual Basic displays each of the temperatures in the text box and
prints an average at the bottom. Your screen looks similar to this:
- Click the Close button on the form to end the program.
Creating a Dynamic Array
As you can see, arrays are quite handy for working with lists of numbers, especially if you
process them by using For... Next loops. But what if you’re not sure how much array space
you’ll need before you run your program? For example, what if you want to let the user
choose how many temperatures are entered into the Fixed Array program?
Visual Basic handles this problem efficiently with a special elastic container called a dynamic
array. Dynamic arrays are dimensioned at run time, either when the user specifies the size of
the array or when logic you add to the program determines an array size based on specific