One Dimensional Arrays

A 1D array is a data structure that can be thought of like a list. For example if you were asked to create a program that stores five names you might think that you could use 5 variables, what about a program that stores 20 or even 1000?

To create an array we use the DIM command but we add in a new piece of information.

DIM Number(5) as Integer

The (5) tells VB that you want to create an array that ends at position 5, this gives the array 6 positions as there is a position 0, as shown below.

  • Number(0) = 1
  • Number(1) = 2
  • Number(2) = 3
  • Number(3) = 4
  • Number(4) = 5
  • Number(5) = 6

A FOR loop is often used when we want to work with all the values in an array

  • For Position = 0 to 5
  • Number(Position)=Position+1
  • Next

The two pieces of code above produce exactly the same results.

The 1D Array is the only data structure we use in Higher Computing