Search code examples
vbadllvariadic-functions

Variable argument list with Visual Basic?


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

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?

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


Solution

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

    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