View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.sdk,microsoft.public.excel.programming
Jerry W. Lewis Jerry W. Lewis is offline
external usenet poster
 
Posts: 837
Default How Many Arguments?

Is it possible in a C based .xll function that takes a variable number
of arguments, to determine how many arguments were actually given?

In VBA

Function NumArgs(ParamArray Args() As Variant) As Integer
NumArgs = UBound(Args()) + 1
End Function

does the trick.

In the FuncSum example function from the SDK's Generic.c I do not see a
corresponding approach. I could loop through px1 through px29 and
determine which ones do not have xltypeMissing; but that would not
distinguish between =FuncSum() and
=FuncSum(,,,,,,,,,,,,,,,,,,,,,,,,,,,,), where in one case no arguments
were given and in the other 29 missing arguments were given.

Also, is it possible to either program or register FuncSum in such a way
that at least one argument must be given before Excel will call the
function? For example the worksheet function SUM produces an error
dialog if you attempt to enter =SUM(); you must give SUM at least one
argument, even if that argument is missing.

I know that it is not possible to exactly reproduce all behavior of
native Excel functions in user defined functions (either VBA or .xll).
For example Excel 3-D references cannot be passed to either type of UDF
(though some have kludged alternative structures to preserve the
functionality). Are these more examples of incompletely supported features?

Jerry