array

A

a

Dear programmer I don't understand the array can any one give very easy
example to understand the types of array ( I can use command button and text
box)

Example

'Don't forget to write notes for me

' the next line will define the array.

Dim a(2) As String

' the next lines define the data of array
a(0) = "1"
a(1) = "2"
a(2) = "3"

And so on

Notes:

The array is very difficult please give me easy example
 
D

Dirk Goldgar

a said:
Dear programmer I don't understand the array can any one give very easy
example to understand the types of array ( I can use command button and
text
box)

Example

'Don't forget to write notes for me

' the next line will define the array.

Dim a(2) As String

' the next lines define the data of array
a(0) = "1"
a(1) = "2"
a(2) = "3"

And so on

Notes:

The array is very difficult please give me easy example


An array is a data structure containing multiple elements of the same type.
When storage for an array is allocated, space for a fixed number of elements
is allocated. Arrays can be one-dimensional (a list of of elements),
two-dimensional (a table of elements) or may even have three or more
dimensions. Each individual element can be accessed by providing a numeric
index or "subscript" for each dimension, so that the location of that
element in the array's storage space can be calculated.

In the simple case, the size or "bounds" of each dimension of the array are
defined when it is declared. It is also possible to declare an array with
dynamic bounds, and later use the ReDim statement to allocate or reallocate
the array with specific bounds.

The statement:

Dim a(2) As String

declare a as a one-dimensional array of String elements. By default, the
array's first and only dimension has a lower bound of 0 (because the lower
bound wasn't specified) and an upper bound of 2. Therefore there are three
elements in the array, and the individual elements can be referred to as
a(0), a(1), and a(2). In those references, the numbers in the parentheses
are the subscripts that identify the specific element in the array.

The array declaration above is equivalent to the statement

Dim a(0 To 2) As String

which declares both the lower bound and the upper bound.

A declaration like this:

Dim i(20, 20) As Integer

defines a two-dimensional array of Integer elements. As declared, unless an
Option Base statement had been used to set a different default low bound, it
would declare an array with 21 x 21 elements, making 441 in all, addressable
by references ranging from i(0, 0) to i(20, 20).

This declaration:

Dim i(1 To 20, 1 To 20) As Integer

declares an array with 400 elements, addressable by references from i(1,1)
to i(20, 20). For this array, a reference to i(0,0) would raise a
"subscript out of range" error.
 
G

George Nicholson

This is oversimplifying a bit, but conceptually, it might help to think of a
single-dimension array as a single column or single row of data in an Excel
spreadsheet.
A table of Excel data (with multiple rows and multiple columns) would be an
array with 2 dimensions.

When declaring an array you (generally) need to specify its size. (how long
and/or how wide).
Dim a(2) As String
Represents a single-dimension array with 3 elements (starting at zero).

This will fill those 3 elements with the specified values:
a(0) = "1"
a(1) = "2"
a(2) = "3"

If Excel had a row zero, you could picture this as filling cells rows 0 thru
2 of *one* column with the specified values (for example: A0:A2). You could
also picture it as being *one* row of data (C1:E1 for example). In either
case, those 3 elements are the only things that exists in the array.

You can now reference those values using the same syntax:
x = a(0) + a(2)

x will equal 13 since the values in the array were specified as text
values. If they had been numeric, x would equal 4.
 
B

BruceM

That made a few things easier to understand for me. Thanks for the succinct
explanation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top