27

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

1
  • 10
    This is not a duplicate, since VBA is not VB6 Commented Oct 30, 2014 at 18:44

1 Answer 1

43

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
Sign up to request clarification or add additional context in comments.

1 Comment

Note: You can mix ParamArray var() As Variant with non-optional arguments. See cpearson.com/excel/OptionalArgumentsToProcedures.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.