# Problem of dictionary of arrays

I am working with the MBSChartDirector which gets its data from a single element array. If I could figure out how to use a two element array, the present issue would not exist. To create a chart that needs several arrays to populate it, I loop through my recordset and create the array of Doubles to send to the chart control. I then assign the array to the first value in a dictionary. I go through the rest of my recordsets creating anywhere from one to six more arrays. Unfortunately, while the key for each dictionary value has the proper name for that array, the dictionary values are all the same (the first one entered). I have read that you can’t have an array of arrays and it appears you can’t have a dictionary of them either. Is this true or am I doing something wrong?

Perhaps a better way of doing this is to process the record sets in a function that would return the array as it is being sent to the chart control.

Are you reusing the same array variable? That would explain what you’re seeing if you are.

Yes. The function would create a new array object each time you called it.

As Tim pointed out, you have to create a new array each time. You can do that by dim’ing the array with a loop, or using `Array` to create a new array.

Method 1:

``````dim d as new Dictionary
for i as integer = 0 to 10
dim arr() as double
arr.Append aValue
d.Value( i ) = arr
next``````

Method 2:

``````dim d as new Dictionary
dim arr() as double
arr = Array( value1 )
d.Value( value1 ) = arr
arr = Array( value2 )
d.Value( value2 ) = arr
...``````

If you just need the value, you can use an array of variant instead of a Dictionary where each element of the array is the array of double.

I had the same problem. See the thread on the RB NUG where this was explained to me and it makes perfect sense. The array is not copied into the dict, only a pointer to it so you must recreate one for each entry - within not outside, the loop. Subtle.

The plugin point of view is simply that the plugin can’t access arrays with more than one dimension. Sorry.

Tim had the answer. I was thinking that redimensioning the array would put new values in it, but that does not happen. Thanks guys.