저는 VBA에서 사용하고 싶은 몇 가지 .NET 클래스를 가지고 있습니다. 그래서 저는 COM과 그 모든 것을 통해 그들을 등록해야합니다. COM 등록 (마침내)을 알아 냈다고 생각하지만 지금은 개체를 만드는 방법에 대한 구문에 대한 도움이 필요합니다. 다음은 내가하려고하는 것을 보여주는 몇 가지 의사 코드입니다.VBA에서 .NET 클래스를 사용하려면 어떻게해야합니까? 구문 도움말!
편집 : 변경 첨부 객체 목록
닷넷 클래스는 다음과 같이 ...
public class ResourceManagment
{
public ResourceManagment()
{
// Default Constructor
}
public static List<RandomObject> AttachedObjects()
{
ArrayList list = new ArrayList();
return list;
}
}
public class RandomObject
{
//
public RandomObject(int someParam)
{
}
}
확인을 대신 ArrayList에 돌아갑니다, 그래서 이것은 내가 싶습니다 것입니다 VBA에서 할주의 할
public class VBAClass
{
public void main()
{
ArrayList myList = ResourceManagment.AttachedObjects();
foreach(RandomObject x in myList)
{
// Do something with RandomObject x like list them in a Combobox
}
}
}
한 가지 RandomObject 공개 defau을하지 않는다는 것입니다 ... (C#으로 입증)하지만 난 방법을 모른다 lt 생성자. 그래서 Dim x As New RandomObject
같은 인스턴스를 만들 수 없습니다. MSDN은 Types must have a public default constructor to be instantiated through COM. Managed, public types are visible to COM. However, without a public default constructor (a constructor without arguments), COM clients cannot create an instance of the type. COM clients can still use the type if the type is instantiated in another way and the instance is returned to the COM client. You may include overloaded constructors that accept varying arguments for these types. However, constructors that accept arguments may only be called from managed (.NET) code.
추가 된 ... 당신은 COM을 통해 기본 생성자가없는 개체를 인스턴스화 할 수 있지만 다른 방법으로 반환되는 경우 여전히 개체 유형을 사용할 수 있다고 말한다 : 여기 내 VB에서 시도 :
Dim count As Integer
count = 0
Dim myObj As New ResourceManagment
For Each RandomObject In myObj.AttachedObjects
count = count + 1
Next RandomObject
글쎄, VBA에서 RandomObject의 인스턴스를 "생성"하려고하지 않았습니다. 나는 ResourceManagement 클래스 (관리되는 .NET) 내에서 생성 된 RandomObjects 목록을 가지고 작업하려고하고있다. – PICyourBrain
오, 사과 내가 그때 질문을 잘못 읽었습니다. 루프에 대한 vba 구문을 알고 싶습니까? 첫 번째 문제는 일반적인 목록을 com 측에 반환 했음에도 불구하고 com이 제네릭을 지원하지 않는다는 것입니다 (컴파일러가 경고를 시작하여이 작업을 수행하려고 했어야합니다). VBA에서 ResourceManagement 클래스에 액세스 하시겠습니까? –
예. VBA 프로젝트에서 .NET 어셈블리에 대한 참조를 추가했습니다.그런 다음 VBA에서 "Dim myObj As New ResourceManagment"를 수행 할 수 있지만 AttachedObjects 메서드는 어떻게 호출해야합니까? – PICyourBrain