Arrays

You have seen how a variable of a given data type is but a name for a memory location that can store a value of that type. Now what would you do if you would like to have a whole bunch of values of the same type stored as compact as possible and have the same name and some indexing scheme to be able to identify any given value? The answer is quite simple: you would have an array.

For example let's consider that you need to operate on five accounts, namely on the balances of these accounts. You could declare a variable for each account that will hold the balance for that account, as in the following example:

Dim balance1 As Decimal
Dim balance2 As Decimal
Dim balance3 As Decimal
Dim balance4 As Decimal
Dim balance5 As Decimal

Or you could ...

Get Visual Basic® .NET by Example 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.