First off, exactly what is an array?
The English dictionary provides the following definition:
1 an imposing or
well-ordered series or display.
2 an ordered
arrangement, esp. of troops (battle array).
3 poet. an outfit
or dress (in fine array).
4 a Math. an
arrangement of quantities or symbols in rows and columns; a matrix. b
Computing an ordered set of related elements.
5 Law a list of
1 deck, adorn.
2 set in order;
3 Law empanel (a
What is the difference between a
variable and a variable array?
A variable holds one bit of information
under a name. A variable array holds more bits of information under a
How can I access the information stored in a array?
Array data is accessed through index. Example:
We will declare an array of variables:
| Dim Countries(4) As String
Countries(0) = “Romania”
Countries(1) = “USA”
Countries(2) = “China”
Countries(3) = “England”
Countries(4) = “Russia”
Obs: in Visual Basic arrays counting
is zero-based. This means that if you declare an array of 2 you will
have an array of three elements, and so on.
Now the variable Countries contains 5
country names. We will now access the third country from this array.
Why can’t I use more variables
instead of arrays?
By using an numeric value instead of a variable name at run time you
- You can dynamically access data.
- By using an resizable arrays you can
store data provided by user.
- You can use them in loops(for..next,
Finding the limits of an array
Now, there are two very important
functions that go hand in hand with arrays. These
function are UBound and LBound (Upper boundary and Lower boundary).
Let’s return now to our Countries
How these two functions can help me use this array?
- The UBound function returns the last
index you can use in a array.
- The LBound function returns the
first index you can use in a array.
a first look these function do not help very much. But imagine that
you use an resizable array. You will find that is very hard too keep
track of the last index of this array. Here is where these functions
really help you.
and Join function
Split and Join functions are available only for Visual Basic version
Split function is used for breaking a string into an array. Example:
have the following string:
are going to school”
will split the first string using space as the splitter.
Words() As String
= Split(“We are going to school”,” ”)
This code splits the string in an array
of words and prints the word 3 and 4 (the array is zero-based) in the
imediate window of Visual Basic.
The Join function is just the
“antonym” of Split function. This function does the exact opposite
We will now make form the “Words”
array a single variable.
| Dim FullText As String
FullText = Join(Words)