vba Visual Basic 的变量参数列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14716385/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 14:53:29  来源:igfitidea点击:

Variable argument list with Visual Basic?

vbadllvariadic-functions

提问by Elmi

assumed I have a DLL that exports functions with variable arguments list like this:

假设我有一个 DLL,它导出带有可变参数列表的函数,如下所示:

int myfunc(int arg1,...)

Here "..." is a undefined number of additional arguments. Can such functions be called out of a Visual Basic application or is VB locked to functions with fixed arguments?

这里的“...”是未定义数量的附加参数。此类函数能否从 Visual Basic 应用程序中调用,或者 VB 是否锁定为具有固定参数的函数?

I'm just asking to avoid a design problem that would lock-out VB programmers...

我只是要求避免一个会锁定 VB 程序员的设计问题......

Thanks!

谢谢!

回答by Peter Albert

In VBA, functions can hand over an undefined number of arguments, so there should be no problem.

在 VBA 中,函数可以传递未定义数量的参数,所以应该没有问题。

Directly in VBA, you'd define a function like this:

直接在 VBA 中,您可以定义这样的函数:

Function SumAll(ParamArray var() As Variant) As Double
    Dim i As Integer
    Dim tmp As Double
    For i = LBound(var) To UBound(var)
        If IsNumeric(var(i)) Then tmp = tmp + var(i)
    Next
    SumAll = tmp
End Function