Arrays in Visual Basic

When a variable is declared with the statement Dim Num As Integer memory is allocated for one integer. If a list of numbers is needed, they can be declared as Num1, Num2, Num3, etc. However, an array is a much easier way to deal with a list of numbers. The statement Dim Num(4) As Integer declares a list of numbers that can be referred to as  Num(0), Num(1), Num(2), Num(3), and Num(4). Notice that there are actually 5 numbers in the list because the first element in an array is always 0. The value inside the parenthesis is called the subscript, or index. One of the advantages of an array is that the subscript can be a variable. For example if we have an integer P with a value of 3, then Num(P) is the same as Num(3). For loops are often used to process an array.


Please study the material at each of the links below.

  1. Scalar Variables vs. Arrays
  2. Example 1: Initialize
  3. Out of Bounds Exception
  4. Arrays of Objects
  5. A lookup example
  6. Julian Date
  7. ReDim: Change the Size of the Array
  8. No Duplicates
  9. Collections
  10. LINQ
Like us on Facebook:

OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 23 2017 18:22:37.