在 Microsoft Access VBA 中使用 .Net DLL

2024-03-14

好的,我有一个使用 Visual Studio 2010 用 C# 编写的程序集。

该Assembly包含一个类,该类包含一个返回Result一词的方法,代码如下:

using System.Runtime.InteropServices;

namespace TestDLL
{
    public class Class1
    {
        [ComVisible(true)]
        public string TestMethod()
        {
            return "Result";
        }
    }
}

属性窗口上“构建”选项卡中的输出部分如下所示:

当我单击“Build”时,我会得到一个 DLL 文件和一个 TLB 文件。我只需浏览该 TLB 文件即可将其添加到 Microsoft Access。

现在,在 Access 中我有一个按钮和一个标签。我想让标签的 Caption 属性等于 testMethod 的结果。我想我需要做类似于下面的事情,但我不确定,任何帮助将不胜感激:

Private Sub btnMain_Click()

    Dim tm As TestDLL
    Dim foo As String

    foo = tm.testMethod

    lblBarr.Caption = foo

End Sub

Thankyou


也许接下来会起作用:

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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Microsoft Access VBA 中使用 .Net DLL 的相关文章

随机推荐