Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 11 Using Arrays to Manage Numeric and String Data 279


a value of 20. Also, notice that there are three sets of braces used in the declaration;
these braces clarify which elements are being assigned and keep them in the proper order.

The following screen shot shows the Visual Studio Code Editor with the three examples of
array literal declarations that I have shown in this section. Notice that the Code Editor is in
debugging mode (or break mode) and the Watch window is visible and shows the contents
of the Waiters array. (Debugging mode and the Watch window were introduced in Chapter 8,
“Debugging Visual Basic Programs .”) A For... Next loop is also being used to display the
contents of the Waiters array in a message box, although you cannot see the results of that
loop on this screen. For... Next loops are excellent tools to process arrays, as you’ll see in the
next section.

Creating a Fixed-Size Array to Hold Temperatures


The following exercise uses a one-dimensional array named Temperatures to record the
daily high temperatures for a seven-day week. The program demonstrates how you can use
an array to store and process a group of related values on a form. The Temperatures array
variable is declared at the top of the form, and then temperatures are assigned to the array
by using an InputBox function and a For... Next loop, which you learned about in Chapter 7,
Free download pdf