简体   繁体   中英

Sending array data from excel VBA to WCF

My problem is, I want to send an array of strings from VBA to WCF.

c# code is :

[OperationContract]    
void SetSomeObjects(string[] data);

Here is the VBA Part

Dim data(2) As String
data(0) = "abc"
data(1) = "def"

Dim service2 As Object
Set service2 = GetObject(ServiceBindingInformation)
service2.SetSomeObjects data

The last line throws VBA

"Type Mismatch Error"

I have no idea why is this happening. Please suggest a way to send array data from VBA to WCF Service If I used object as the argument type, it gives error as shown in the attached screenshot

I think the problem is within C# code.

Once I wanted to sort the array (VBA) based on Linq (C#). Array was passed to UDF in the way one pass an argument to the function/method:

Dim UDF_Array As UDFArrayLinqTest.ArrayLinq
Set UDF_Array = New UDFArrayLinqTest.ArrayLinq

TBL = Array(...)
Range(...) = UDF_Array.ArraySorted(TBL)

The simple UDF in C# was as follow:

public double[] ArraySorted(object tbl)
    {
        object[] obj = (object[])tbl;
        var filtr = from i in obj
                    orderby Convert.ToDouble(i)
                    select Convert.ToDouble(i);

        double[] result = (double[])filtr.ToArray();
        return result;
    }

I don't think it is the best idea but I stopped searching better one after I did that above which was good enough for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM