Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable argument list with Visual Basic? [duplicate]

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

like image 596
Elmi Avatar asked Feb 05 '13 20:02

Elmi


People also ask

What are the two methods to pass arguments in VBA?

You can pass an argument by value if you include the ByVal keyword in the procedure's declaration. Arguments passed by value consume from 2–16 bytes within the procedure, depending on the argument's data type. Larger data types take slightly longer to pass by value than smaller ones.

What is ByRef in Visual Basic?

ByRef in VB.NET means that a reference to the original value will be sent to the function (1). It's almost like the original value is being directly used within the function. Operations like = will affect the original value and be immediately visible in the calling function.

What is ParamArray in VBA?

ParamArray allows you to pass an arbitrary number of arguments to the procedure. A ParamArray parameter is always declared using ByVal. You can supply one or more arguments to a ParamArray parameter by passing an array of the appropriate data type, a comma-separated list of values, or nothing at all.

How do you use ByRef in VBA?

ByRef in VBA is a function called as by reference where we provide a reference to any arguments in our code, when we make custom functions and we want to use the value of any variable which is defined earlier before the function we use ByRef function, the syntax to use is simple as Function Function-Name(ByRef Variable ...


1 Answers

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
like image 188
Peter Albert Avatar answered Sep 30 '22 17:09

Peter Albert