I am making a COM for Excel with C#.
Parameter.cs
ClassInterface (ClassInterfaceType.None)
ComDefaultInterface (type of (IParameter))]
ComVisible (true)
public class parameter
{
public Member [ ] Members {get;set;}
public Parameter()
{
Members = new Member [2];
Members[0] = new Member() {Name="A"};
Members[1] = new Member() {Name="B"};
Members[2] = new Member() {Name="C"}
}
}
IParameter.cs
InterfaceType (ComInterfaceType.InterfaceIsDual)
ComVisible (true)
public interface IParameter
{
Member [ ] Members {get;set;}
}
When generating an instance of a member class on the VBA side, it is stated as follows:
Dimparam as Object
Set param=CreateObject("Parameter")←Successful
Dim count as Integer
count=UBound(param.Members)←count contains 2
MsgBox param.Members(0).Name←Error!0th element inaccessible
Although the explanation is longer, the UBound() value is returned correctly depending on the number of elements in UBound(param.Members above, but an error occurs when trying to access each element.
The error message is as follows:
Wrong number of arguments or invalid property assignment
How can I access each element?
c# vba com
In VB, UBound is not "number", but "maximum number of subscripts".
In the original C# code, for "new Member[2]" (number of elements 2), there is a code that expects "member[2]=...", but what is the number of elements?
If the number of elements 2 is correct and the LBound is 1, then the subscripts are 2 arrays that can be accessed by 1 and 2.Please check out LBound as well.
I haven't tried it, but once I get param.Members in Variant, it might work.
Dim vAs Variant
Dim As Member
v=param.Members
Fori= LBounds(v) To UBounds(v)
Set m=v(i)
Next
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
611 GDB gets version error when attempting to debug with the Presense SDK (IDE)
578 Understanding How to Configure Google API Key
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.