I am currently using CallByName to dynamically call methods. There are several methods that I collect daily from a table on the server along with the arguments. For this reason, I am sending an array of arguments to CallByName, and not to the param array, since I do not know the number of arguments to execute. Given that CallByName expects a paramarray, I use the private declare function to bypass the VBA type definition.
Private Declare PtrSafe Function rtcCallByName Lib "VBE7.DLL" ( _ ByVal Object As Object, _ ByVal ProcName As LongPtr, _ ByVal CallType As VbCallType, _ ByRef Args() As Any, _ Optional ByVal lcid As Long) As Variant Public Function CallByNameMethod(Object As Object, ProcName As String, ByRef Args () As Variant) AssignResult CallByNameMethod, rtcCallByName(Object, StrPtr(ProcName), VbMethod, Args) End Function Private Sub AssignResult(target, Result) If VBA.IsObject(Result) Then Set target = Result Else target = Result End Sub
This works when I pass an object where the method changes its basic properties. However, there are some methods in which I pass an object and a method that changes the values ββof the passed arguments. For example, I pass an array with the following arguments
Dim Name as String, Value1 as double, Value2 as double, Value3 as double Dim Array(3) as Variant String = "Name" Value1 = 0 Value2 = 0 Value3 = 0 Array(0) = Name Array(1) = Value1 Array(2) = Value2 Array(3) = Value3
When I pass this array, the method returns the array back with the same values, but I expect double type values ββfor Array (1), Array (2), Array (3). Any ideas?