Page

4.8.0- Arrays

  by NT Community Manager.
Last Updated  by Jim Minatel.  

PublicCategorized as 04. Variables.

Not tagged.
<< 4.7.6- Giving it a Quick TrimChapter44.8.1- Declaring Arrays >>

Arrays

Variables are fine for storing individual items of data. However, they're not so good if you wish to store many items of similar information. In this case, you'll need to use an array. Arrays are used to store a series of related data items, which are related by an index number at the end. You could use them to store the names of the Marx brothers, for instance:

 

strMarx(0) = "Groucho"

strMarx(1) = "Harpo"

strMarx(2) = "Chico"

strMarx(3) = "Zeppo"

strMarx(4) = "Gummo"

strMarx(5) = "Karl"

 

However, you don't have to store something in each item of the array, and you don't even have to store it sequentially:

 

strHouse(1) = "Mr Jones"

strHouse(3) = "Mr Goldstein"

strHouse(4) = "Mrs Soprano"

Arrays are particularly useful if you want to manipulate a whole set of data items as though they were all one item. For example, if you want to adjust the pay rates for a set of five employees, then the difficult way is the following:

 

intExtraPay = 10

intEmployeePay(0) = intEmployeePay(0) + intExtraPay

intEmployeePay(1) = intEmployeePay(1) + intExtraPay

intEmployeePay(2) = intEmployeePay(2) + intExtraPay

intEmployeePay(3) = intEmployeePay(3) + intExtraPay

intEmployeePay(4) = intEmployeePay(4) + intExtraPay

 

The following much simpler code utilizes your array structure, and has exactly the same effect:

 

intExtraPay = 10

For intLoop = 0 to 4

  intEmployeePay ( intLoop) = intEmployeePay(intLoop) + intExtraPay

Next

 

Arrays are much more versatile than plain regular variables when dealing with sets of data.

 

We will be discussing For ... Next loops in the next chapter .

<< 4.7.6- Giving it a Quick TrimChapter44.8.1- Declaring Arrays >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |