Visual Basic: Windows Programming
Learn Visual Basic in FREE step-by-step lessons.
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.
- Example 1: Initialize
- Out of Bounds Exception
- Arrays of Objects
- A lookup example
- Julian Date
- ReDim: Change the Size of the Array
- No Duplicates
- Collections
- LINQ
Glossary for arrays lessonFull Glossary