Link to home
Start Free TrialLog in
Avatar of dc_sava
dc_sava

asked on

Multidimensional Arrays

I'm a little confused by multidimensional arrays.
Bear with me I'm currently going through the process of figuring out the boundaries of notes.
(which is a painful process)... I apologise if this is confusing to read, but I am confused in writing it.  :o)

i.e. If I have an array listed as MyArray(1,1)
With entries:
MyArray(0,0) = "Fred, Manly"
MyArray(0,1) = "Fred, Man"
MyArray(1,0) = "Rita, Womanly"
MyArray(1,1) = "Rita, Woman"

I have the following questions:
Can I change an entry without needing to define both values again?  Lets say I want to change Fred to Bob, must I enter
MyArray(0,0) = "Bob, Manly"
MyArray(0,1) = "Bob, Man"
Or is there a way to change only MyArray(0)Fred to Bob without needing to re-define the other entries?

Alternatively can they be accessed individually?  Output to a field on a form displaying Doc.Output = MyArray(1,0) would give:  Rita, Womanly  

Can I just access the second value?

Basically what I would like to achieve is that I could have one field representing the person i.e. Rita and another field representing the entries associated with her. i.e. Womanly  and  Woman.

Could someone please enligten my understanding (or lack thereof).


Thanks
David.
Avatar of sloeber
sloeber
Flag of Belgium image

Hello David,

Little remark, if you dont want to start from 0, you can add Option Base 1
If your array is MyArray(1,1) then you have a two dimensional array.
For assigning a value to each element.
You do the follow
MyArray(0,0) = 1
MyArray(1,0) = 2
MyArray(0,1) = 3
MyArray(1,1) = 4
So, you have generate a table MyArray(x,y) where x are the rows and y are the columns.
So, if you want to specify a cell, you give the row and the column.
If you say MyArray(0,1) = "Fred, Man"
Then you give the first row, second cell, two values Fred and Man
It is not so that you have set two different cells, you've only set one cell.

I hope that it's now a little bit more clear to you.

Greets,
Sloeber
ASKER CERTIFIED SOLUTION
Avatar of sloeber
sloeber
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Okay, here's the way you do it :
Let's say you have two people with 3 properties so you would have an array defined like this :
Dim MyArray(2,3) as String
To set the elements you would do the following :
MyArray(0,0)="Bob"
MyArray(0,1)="Manly"
MyArray(0,2)="Man"
MyArray(1,0)="Rita"
MyArray(1,1)="Womanly"
MyArray(2,1)="Woman"

Now let's say you want to change the name from Bob to Fred.
You only need to change MyArray(0,0) so the statement is
MyArray(0,0)="Fred"
Now you can put all individual values in different fields by using the correct index.

What this array does is actually create a virtual table :
(I hope this will display readable)
  | 0    | 1       | 2
----------------------------
0 | Bob  | Manly   | Man
1 | Rita | Womanly | Woman

You can reference any element in the table by using the correct coordinates, so for examplke MyArray(0,1) equals "Manly" and MyArray(1,2) equals "Woman".

So in short you will want to have every seperate element in a seperate row, column in your virtual table. Then you could look upon this as the first column, being all the names, the second column the first name property and the third column the second name property.

I hope this clears up things a bit for you. If you need any further assistance clarification, just let us know.
Avatar of HemanthaKumar
HemanthaKumar

Avatar of dc_sava

ASKER

Sloeber,

Thank-you for your response. It makes thing a lot clearer.
Now I may actually be able to use them properly.

Thanks also to Jerrith your response was as equally understandable.

Cheers
David.