Calc Sum function implementation in Basic

I’m trying to learn Basic by example, specifically dealing with ranged input. So, I’d like to see how the SUM function is implemented.

Where can I find the Macro definition for the Calc SUM function? I was browsing the Basic macros in LibreOffice Macros & Dialogs > SFDocuments > SF_Calc > DSum

It looks like DSum calls _DFunction, which then calls com.sun.star.sheet.GeneralFunction.SUM.

Welcome!

Let’s decide which of the functions we are going to talk about: the SUM() function or the DSUM() function. The principle of using the built-in functions from Basic is the same, the calls of these two functions will differ only in the set of parameters. In order not to get confused even more, let’s choose one of them.

So which one?

What makes you think that spreadsheet functions are implemented in Basic?

Yet another one :p

There is no macro definition for SUM(), which is a Calc core code function. What the ScriptForge SF_Calc DSum in _DFunction does is calling sheet::XSheetOperation:: computeFunction() with the enum value com.sun.star.sheet.GeneralFunction.SUM, which is one of a few functions available. Unfortunately the help on these SF_Calc functions is incomplete and does not tell that values of filtered and hidden rows and hidden columns are excluded, the same as in the status bar functions. This is not how SUM() behaves, which does not exclude values, and also not how SUBTOTAL(9;…) behaves, which only excludes filtered rows.

Ah okay. So I understand that my question doesn’t make sense since SUM() is not implemented in Basic.

Well, it is easier to summarize the passed data array by a loop in the StarBasic - instead of calling the fuinction SUM().
Of course you can call the Calc cell functions from StarBasic:
https://help.libreoffice.org/latest/eo/text/sbasic/shared/calc_functions.html

You must handle the passed DataArray, and not the Cell/Range References.