Passing Array from C#/.NET back to VBA

128 views
Skip to first unread message

Jay Martin

unread,
Aug 25, 2023, 4:47:29 PM8/25/23
to Excel-DNA
Hi,
I'm trying to send an Array (of ushort[] ) values to be used in VBA.

My C# is returning a Array object 

public static object HORDoAcquisition(bool shutterOpen)
        {
            if (_currentDev == null)
                return null;
            var data = _currentDev.AcquireOneSpectra(shutterOpen);
            return data;
        }

My VBA code is as follows

Function GetData() As Object

Dim data As Object
Set data = Application.Run(cmdDoAcquisition, True)

GetData = data

End Function

"data" above doesn't appear to receive the 1d array of ushort values..

Any help / direction is greatly appreciated.

Govert van Drimmelen

unread,
Aug 26, 2023, 11:51:57 AM8/26/23
to Excel-DNA
Hi Martin,

That ushort[] array data type is not supported by Excel-DNA.
I suggest you convert to a double[] before returning.

-Govert
Reply all
Reply to author
Forward
0 new messages