添加一个TLB作为参考来调用函数VS使用“运行”:有什么区别? [英] Difference between : adding a tlb as reference to invoke function VS using 'Run'?
问题描述
假设我有一个.net库的一类(TestClass的)与功能添加。我通过编写VBA插件访问该Excel中。我想知道访问FUN1的以下两种方法之间的差异。
Assume I have a .Net library with a class(TestClass) with a function 'Add'. I am accessing this in Excel by writing a VBA addin. I want to know the difference between the following two ways of accessing FUN1.
-
添加了TLB作为参考,并使用新的作为。
Add the tlb as reference and use New as in
昏暗的obj =新MyLibrary.TestClass
Dim obj = New MyLibrary.TestClass
returnval = obj.Add(5,5)
returnval = obj.Add(5,5)
Regasm是NET的DLL和使用运行方法,在
Regasm that .Net dll and use Run method as in
returnVal =运行(添加,5,5);
returnVal = Run("Add", 5, 5);
我有很多的code,我看到这个类似的访问功能的方式感到很困惑是如何工作的。
I have a lot of code where I see this similar way of accessing a function and am really confused how this works.
如何2工作,将它的工作或什么是neccesary使2的工作是这样的。
How does 2 work, will it work or what is neccesary to make 2 work like this.
推荐答案
您需要与Dim语句在code段的作为关键字替换=。这工作(假设类与COM正确注册):
You need to replace the = with the As keyword for the Dim statement in your code snippet. This works (assuming that the class is registered properly with COM):
Sub AccessExternalUdf()
Dim obj As New MyNamespace.MyClass
result1 = obj.MyMethod
result2 = Run("MyMethod")
End Sub
之差(以上由@Hans的规定)是早期与晚期(运行)的结合。
The difference (as stated above by @Hans) is early versus late (Run) binding.
这篇关于添加一个TLB作为参考来调用函数VS使用“运行”:有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!