Arrays are simply Lists.
Consider this Grocery list, it is a One Dimentional Array.
Eggs
Milk
Bread
Letuce
Hamburger
Swiss Cheese
etc.
To represent this in code we have to tell the computer that we want to keep a list of Related Items. We do this by Declairing The Array and setting it's data type, which allows the computer to set aside the EXACT amount of memory needed for that list.
in most programming languages an Array is represented by a Designation similar to Dim myArray(
n) where
n = any number. If you replace
n with a value, then memory is reserved for
n items.
example simple 1 Dimentional Array
CODE
Dim Groceries(20) as String
'Assign Values to the Array
Groceries(0) = "Eggs"
Groceries(1) = "Milk"
Groceries(2) = "Bread"
Groceries(3) = "Letuce"
Groceries(4) = "Hamburger"
Groceries(5) = "Swiss Cheese"
etc.
But for most people an Array is best Visualized in two dimentions Length (X) and Height(Y)
Think of a Chess Board. Each Box can have a piece in it, and each piece is at a specific box. By creating an Array called Chess(8,8) we can place data at each Addressed Box representing the piece at that location. There are 64 locations in this Array. We could create a single dimention Array of 64 units ie Chess(64) and have the same size Array, but this would make programming the interaction between pieces very dificult. by making the 2D Array we can Visualize The Board and easily represent movements and associations by simple math. ie
Chess(4,4) = BlackQueensPawn
to move the piece one place forward we simply add 1 to the Y address position and place the data there
Chess(4,5) = BlackQueensPawn
And erase the value where it was
Chess(4,4) = ""
note: Computer Arrays always start with a beginning position of 0, so to a computer the Starting Position for BlackQueensRook would be Chess(0,0) top left corner, or you could call it the bottom left corner if you wished. The point is that each square on the board is represented by a place identifyer, or Address,
Chess(0,0) = BlackQueensRook
Chess(0,1) = BlackQueensKnight
Chess(0,3) = BlackQueensBishop
and so on.
In a one dimentional array, the Y value is always 0 therefore, it need not be addressed in code. therefore a 1 dimentional Array is always a horizontal list. City = List(X) {read as "City equals List at X}
a Two Dimentional Array would be City = Box(X,Y) {read as City equals Box at X by Y.}
a Three Dimentional Array would Be City = Cube(X,Y,Z) {read as City equals Cube at X by Y by Z}
If you haven't caught on yet a Three Dimentional Array can be used to set the location of a value in a 3D environment
If you wanted to construct a Four Dimentional Array, it could represent the city at T by X by Y by Z or City(
T,X,Y,Z)
N for Name. So you could address the city as
City(
Time,Longitude,Latitude,Altitude) and so on.
Not so important today as it was 20 years ago, but Each dimention you add to an equally sized array ie (2,2) (3,3) (5,5,5) etc. increases the amount of memory used by a factor of the value.
A (2,2) Array will use 4 memory addresses, a (2,2,2) will use 8 and (2,2,2,2) would use 16 memory addresses and so on.
(4,4) = 16
(4,4,4) = 64
(4,4,4,4) = 256
if you will notice these are all the "MAGIC COMPUTER NUMBERS" because we are basically dealling with BINARY when we use a two dimentional Array. This is exactly how the computer itself keeps track of everything. Memory is a very large Three Dimentional Array. Each Bit in memory has a specific address in this Array. The computer simply keeps track of which memory addresses are related to each other and they each simply hold a 1 or a 0.
Memory at RamChip by ByteLocation by BitPosition as Binary
Memory(RamChip,ByteLocation,BitPosition) as Binary
Memory(1,2563,61) = 1
Memory(1,2563,62) = 0
Memory(1,2563,63) = 1
etc.
I hope this helps.
This post has been edited by KeyWiz: 13 Nov, 2006 - 02:27 PM