Calc macro in basic

My 2 systems are:
Linux Mint and Fedora 40
On both I have Libre-Office version 24.2.4.2

I have some knowledge of C++ and C# (on Windows)

I am trying to develop macros in LibreOffice that will handle some hydraulic calculations for me, if I can get past this very basic issue.

My macro looks like this
REM ------------ mytest
Public Function mytest(A as Double,B as Double) as Double
'Just a test of function
mytest = A * B
End Function

This will not work when I use it folows:
In a cell with two other cells selected aka =mytest(C1:D1) …result is #NAME?
In a cell with two numbers aka =mytest(2,2) …same result of #NAME?
In a cell with two numbers split aka =mytest(2:3) or =mytest(2;3) … again same result

What is wrong or what setting must be changed, as I have seen similar simple examples that will also not work for me.

Thanks
Geurt

Also interesting, where it is located. I can say, that putting it into My Macros & Dialogs/Standard/Module1, it definitely works using the correct locale-independent =mytest(2;3) (or =mytest(C1;D1)) syntax. It would also work using =mytest(2,2) in locales that use comma as argument separator. It needs to treat the first argument as an array (and have the second argument optional), if you want to pass ranges as a single argument. And the 2:3 spreadsheet syntax is basically for whole rows 2 to 3, potentially returning an array of two rows by 16K columns, which is unlikely what you meant.

Hi Mike
I will check to have it in the same place and will revert.

Thanks
Geurt

Hi Mike, I moved the macro from a library I created (aka gbLib/Module1) to “My Macros & Dialogs/Standard/Module1” and then it worked as you indicated.

Thanks for that and help appreciated.

I now need to go and read up on doing own libraries etc.
Cheers
Geurt

You may use other libraries for your code, as you feel convenient. However, you must use Standard libraries (both shared, and per-document) as interface libraries: i.e., to define the top-level functions that will actually be used as user-defined spreadsheet functions (UDFs). They may do only a little work: just make sure to load needed implementation libraries, and then call the functions doing actual work from there. Specifically, Calc code explicitly only loads these Standard libraries (well, for MS documents, also the document’s VBAProject library), when creating the list of the UDFs, hence this requirement.

1 Like