multidimensional array not getting passed from function

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
In the following function I build a 5 by 2 array. the syntax is

Code:
function alpha( code)

dim ancestors(5,2)
(code)

dim result(11)
result(9) = ancestors

end function

sub 

dim ancestors5(5,2)
alpha_result = alpha( code )

ancestors5(5,2) = alpha_result(9)


end sub


As you can see from the screen shots there is definitely something in the alpha_result(9) array but it is not getting passed on to the ancestors5 array.

Screenshot2014-10-05at105328PM_zps955e29da.png

Screenshot2014-10-05at105359PM_zps532709dd.png
 
I think what you mean is on the second screen shot on the left hand side, there is in fact an ancestors5(1) but that just refers to the first of 5 different members of the array, each having 2 members. So the ancestors5 arrays was still called as (5,2)
 
Upvote 0

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
After a confusing read, I *think* you are misunderstanding how you assign to arrays. I think it should be as follows:
Code:
dim ancestors5
ancestors5 = alpha_result(9)
 
Upvote 0
All I mean is:
1. That's clearly not real code you posted, since it makes no sense. (it's also not the same as what you posted at SO)
2. You said that the array is populated in one routine but there are no values present when stepping through. However, the images you post in support of that relate to different elements of the ancestors5 array. The first code puts an array into ancestors(5, 2) (which is the 6th 'row' and 3rd 'column' of your array) but your second picture shows the elements of ancestors5(1). Since they are not the same element, the pictures don't really demonstrate anything.
 
Upvote 0
Problem solved. My mistake was that in the sub I declared arr1 as arr1(3,2) when I should have been declaring it as arr1(). That was my problem. Here is a simplified version of the code that works.

Code:
Function alpha(str As String) As Variant


Dim str2 As String, arr1(3, 2) As Variant


arr1(1, 1) = "hey"
str2 = "you"


Dim result(2)


result(1) = str2
result(2) = arr1


alpha = result


End Function




Sub call_multidimensional_array()


Dim str As String, result(), arr1() As Variant, x As Integer


result = alpha(str)


str = result(1)
arr1 = result(2)






End Sub
 
Upvote 0

Forum statistics

Threads
1,215,987
Messages
6,128,122
Members
449,424
Latest member
zephyrunimpressively

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top