O'Reilly logo

Special Edition Using Microsoft® Visual Basic® .NET by Jeff Spotts, Brian Siler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Arrays

All the variables discussed so far have been single-instance variables. Often, however, you may find it very useful to work with arrays. An array is a group of variables of the same type, sharing the same name. In this way, processing groups of related areas is easy. For example, you might want to have a group of variables that tracks the sales in each of your company’s four regions. You can declare a decimal variable for each region, plus one for the total sales across all regions, like this:

Dim Reg1Sales, Reg2Sales As Decimal 
Dim RegSales3, Reg4Sales As Decimal 
Dim TotalSales As Decimal 

Then, if you want to calculate the total sales for all regions, you might use this code:

 TotalSales = Reg1Sales + Reg2Sales + Reg3Sales + ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required