25

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...

pppery
  • 3,731
  • 22
  • 33
  • 46
Elmi
  • 5,899
  • 15
  • 72
  • 143

1 Answers1

40

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
Peter Albert
  • 16,917
  • 5
  • 64
  • 88
  • 3
    Note: You can mix `ParamArray var() As Variant` with non-optional arguments. See http://www.cpearson.com/excel/OptionalArgumentsToProcedures.aspx – ChaimG Nov 28 '19 at 19:52