I have an array of arrays arrAggregatedArrays(1 to 8)
I can call a sub like this:
call sub(ArrNewClient)
But I get a compile error: "Type Mismatch" if I try this:
call sub(arrAggregatedArrays(1))
Why? And is there a way around it?
and why does it not recognise arrAggregatedArrays(1)
as an array even though it will perform functions like UBound
on it like normal?
Public arrAggregatedArrays() As Variant '/ Holds all the sheet-Data Arrays
'/ Declared in a seperate module
ReDim arrAggregatedArrays(1 To 8)
arrAggregatedArrays(1) = arrNewClient
arrAggregatedArrays(2) = arrExistingClient
arrAggregatedArrays(3) = arrGroupSchemes
arrAggregatedArrays(4) = arrOther
arrAggregatedArrays(5) = arrMcOngoing
arrAggregatedArrays(6) = arrJhOngoing
arrAggregatedArrays(7) = arrAegonQuilterArc
arrAggregatedArrays(8) = arrAscentric
Call FilterSheetArrayForColumns(arrAggregatedArrays(1))
Public Sub FilterSheetArrayForColumns(ByRef arrCurrentArray() As Variant)
and a screenshot:
Arrays can be passed as arguments to method parameters. Because arrays are reference types, the method can change the value of the elements.
To pass an entire array to a function, only the name of the array is passed as an argument. result = calculateSum(num); However, notice the use of [] in the function definition. This informs the compiler that you are passing a one-dimensional array to the function.
Method 1: Using the apply() method: The apply() method is used to call a function with the given arguments as an array or array-like object. It contains two parameters. The this value provides a call to the function and the arguments array contains the array of arguments to be passed.
Arrays are not passed by value because arrays are essentially continuous blocks of memmory. If you had an array you wanted to pass by value, you could declare it within a structure and then access it through the structure.
You can create a Variant
array in one of two ways:
Dim v1() As Variant
Dim v2: v2 = Array()
With the former, you receive the array as a subroutine parameter using the v1()
notation, like with any other data type array in VBA. With the latter, you'll need to receive it as a normal variable, without the array notation.
Variants are special because they can hold many types, including array types, which is why the v = Array()
syntax works. When done this way, they should be treated like any other variable and passed that way in and out of subroutines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With