x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 193

# 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.
0
dc_sava
1 Solution

Commented:
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
0

Commented:
example
what I've done before is this

| 0  |  1
----------------
0  | 1  |  3
----------------
1  | 2  |  4

If you want

MyArray
|  0   |  1     |   2
--------------------------------
0  | Fred | Man    |   Manly
---------------------------------
1  | Rita | Woman  |   Womanly

MyArray(0,0) = "Fred"
MyArray(1,0) = "Rita"
MyArray(0,1) = "Man"
MyArray(1,1) = "Woman"
MyArray(0,2) = "Manly"
MyArray(1,2) = "Womanly"

So if you want to access Womanly, then
doc.output = MyArray(1,2)
...................

Greets,
Sloeber

0

Application EngineerCommented:
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.
0

Commented:
0

Author Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.