Hi Guys,
I am having a bit of a problem. I have a function which passes an array by reference. The Array is unallocated. The purpose of the function is to increase the array size by one as needed by the program. Arrays passed by reference should reflect any changes made by the function. This is not happening. The redim and redim preserve modifications made by the function are only visible inside the function. Once my code exits the function and returns to the main body of code the array shows that it is still unallocated and produces and error 9 subscript out of range. The only way I can get the function to preform as expected is to pass the array out of the function. Not sure what's going on here. Any help would be appreciated. Here's the code.
Code:
Private Function Test(aImageArray As Variant) As Variant
On Error Resume Next
If IsArray(aImageArray) Then
If IsError(LBound(aImageArray, 1)) Then
Select Case Err.Number
Case 9
ReDim aImageArray(0)
End Select
Else
ReDim Preserve aImageArray(UBound(aImageArray) + 1)
End If
End If
Debug.Print UBound(aImageArray)
Test = aImageArray
End Function
When coded like this the code functions as I want, but I should not have to pass the array out in order for the array to be resized. What's going on?