Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have similar problems with <code>Type mismatch</code> error only if I declare array variable in VBA in this way:</p> <pre><code>Dim anotherArray() As Variant </code></pre> <p>but the error disappears if the variable is defined in this way:</p> <pre><code>Dim anotherArray As Variant </code></pre> <p>Some other differences between your and my similar solutions are:</p> <pre><code>//C#- my solution- without array[] definition: public object[] ReturnSomeArray(object someArray) //VBA- my solution -without array() definition: Dim someArray As Variant </code></pre> <p><strong>EDIT: 2013-08-28</strong></p> <p>Working with <strong>C#-Excel-Interop</strong> I prefer try&amp;test way of searching solution. If anything works then I stick to it and sometime I miss to indicate the source of the solution or logic.</p> <p>Below you will find code which includes <code>LINQ</code> to operate with arrays. These code snippets works in both direction- get data from C# to VBA >> pass it back to C# for sorting >> return to VBA. I hope it will help you more to finally solve your problems.</p> <p><strong>First: some C# code</strong></p> <pre><code> public object[] GetSomeArray() { return new object[] { 5, 2, 1, 7, 9, 1, 5, 7 }; } public double[] ArraySorted(object tablica) { object[] obj = (object[])tablica; var filtr = from i in obj orderby Convert.ToDouble(i) select Convert.ToDouble(i); double[] wynik = (double[])filtr.ToArray(); return wynik; } </code></pre> <p><strong>Second: some VBA code</strong></p> <pre><code>Sub qTest_second_attempt() 'declare array variable Dim tmp() 'and other variables Dim addr As String addr = "UDFArrayLinqTest.ArrayLinq" 'get references Dim service1 As Object Set service1 = CreateObject(addr) 'get array from C# tmp = service1.GetSomeArray() 'pass this array to C# back to sort it Dim someArray As Variant someArray = service1.ArraySorted(tmp) 'check the result in Immediate window Debug.Print Join(WorksheetFunction.Transpose(WorksheetFunction.Transpose(someArray))) 'result: 1 1 2 5 5 7 7 9 End Sub </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload