在 Microsoft Access VBA 中使用 .Net DLL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8849001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using a .Net DLL in Microsoft Access VBA
提问by JMK
Ok so I have an assembly, written in C#, using Visual Studio 2010.
好的,我有一个使用 Visual Studio 2010 用 C# 编写的程序集。
This Assembly contains one class, which contains one method which returns the word Result, the code is below:
该程序集包含一个类,该类包含一个返回单词 Result 的方法,代码如下:
using System.Runtime.InteropServices;
namespace TestDLL
{
public class Class1
{
[ComVisible(true)]
public string TestMethod()
{
return "Result";
}
}
}
The output section in the Build tab on the properties window looks like so:
属性窗口中 Build 选项卡中的输出部分如下所示:
When I click on Build, I get a DLL file and a TLB file. I can add this TLB file to Microsoft Access simply by browsing to it.
当我点击 Build 时,我会得到一个 DLL 文件和一个 TLB 文件。我只需通过浏览即可将此 TLB 文件添加到 Microsoft Access。
Now, in Access I have a button and a label. I want to make the Caption property of my label equal to the result of testMethod. I'm thinking I need to do something similar to below but I'm not sure, any help would be much appreciated:
现在,在 Access 中,我有一个按钮和一个标签。我想让我的标签的 Caption 属性等于 testMethod 的结果。我想我需要做一些类似于下面的事情,但我不确定,任何帮助将不胜感激:
Private Sub btnMain_Click()
Dim tm As TestDLL
Dim foo As String
foo = tm.testMethod
lblBarr.Caption = foo
End Sub
Thankyou
谢谢
回答by Arvo
Maybe next will work:
也许接下来会起作用:
Private Sub btnMain_Click()
Dim tm As TestDLL.Class1
Dim foo As String
Set tm = New TestDLL.Class1
foo = tm.testMethod
lblBarr.Caption = foo
End Sub