【问题标题】:cannot convert from system.collections.generic.list to string to Vba.collections无法从 system.collections.generic.list 转换为字符串到 Vba.collections
【发布时间】:2017-10-25 21:44:07
【问题描述】:

我想将一个 int 列表从 C# 传递给一个用 vb6 编写的 dll。在vb6中函数原型如下:

Public Function FamIdentify(agentList As Collection, strName As String, strIdentifyTemplate As String, strIP As String) As Boolean

从C#我调用这个函数如下:

public Boolean IdentifyFinger(String name, String SampleModel, String REMOTE_ADDR) 
{ 
List<int> agentList = new List<int>(); 
// insert some element to this list
FamServer.FamApp famApp = new FamServer.FamApp(); 
Boolean flag = famApp.FamIdentify(ref agentList, ref name, SampleModel, REMOTE_ADDR);
 return flag ; 
}

对于这个编码,我遇到了这个错误

cannot convert from system.collections.generic.list to string to Vba.collections

如何将列表从 C# 传递到 vb6 ?请帮我 。

【问题讨论】:

  • 尝试转换为System.Collections.ArrayList - 这种类型可以通过CreateObject() 方法暴露给VBA。
  • 你的评论我不清楚。你能解释一下吗?
  • 在 C# 中创建一个 ArrayList,用 List 中的值填充它,在 VBA 代码中创建一个 ArrayList,将 ArrayList 传递给 VBA...
  • 为什么不直接使用.toArray() 方法并作为数组传递呢?
  • 我将使用数组的概念。只是尝试使用列表。如果我无法使用 list 执行此操作,那么我将使用 array 。

标签: c# asp.net vba vb6


【解决方案1】:

您需要创建Microsoft.VisualBasic.Collection,从List 添加值,然后才将其传递给函数。我认为,没有直接转换为Collection

Microsoft.VisualBasic.Collection agentCollection= new Microsoft.VisualBasic.Collection();
agentList.ForEach(x=> agentCollection.Add(x));

Boolean flag = famApp.FamIdentify(ref agentCollection, ref name, SampleModel, REMOTE_ADDR);

【讨论】:

  • 命名空间 'Collection' 的类型在命名空间 'Microsoft.VisualBasic' 中不存在。 (您是否缺少程序集参考?)
  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Microsoft.VisualBasic.dll 或类似的地方
  • 无法从 Microsoft.VisualBasic.Collection 转换为 VBA.Collection。
  • 所以它不是 Visual Basic,它是 Visual Basic for Applications...我无法想象为什么要使用 VBA 类型集合,但您可以查看 VB 项目 references 并查看这个 VBA dll来自
  • 我的 VBA 参考可以在这里找到 `C:\Program Files (x86)\Common Files\Microsoft Shared\VBA`
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 2013-06-13
  • 1970-01-01
相关资源
最近更新 更多