使用Visual Basic的可变参数列表? [英] Variable argument list with Visual Basic?

查看:65
本文介绍了使用Visual Basic的可变参数列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

int myfunc(int arg1,...)

此处 ...是未定义数量的附加参数。可以从Visual Basic应用程序中调用此类函数,还是可以将VB锁定为具有固定参数的函数?

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?

我只是想避免某个设计问题会锁定- VB程序员...

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

谢谢!

推荐答案

在VBA中,函数可以传递不确定数量的参数,因此应该没有问题。

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:


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

这篇关于使用Visual Basic的可变参数列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆