Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to call LO Calc functions from a LO Basic function (macro)?

From within the implementation of a LibreOffice function (i.e. macro), I would like to test whether the content of a cell (passed as a parameter) is a number or not.

Function myFunction(a,b,c)
If not ISNUMBER(a) Then
    myFunction = "NaN"
Else
    REM Calculations here
    myFunction = result
End If
End Function

I've found the LibreOffice Calc function ISNUMBER() that does exactly what I want, but I don't know how to call it from the implementation of my LibreOffice Basic function… Upon execution, the implementation given above would show a message box with the error message BASIC runtime error. Sub-procedure or function procedure not defined.

I've also come across the LO Basic function isNumeric() but it does not have exactly the same behavior. In particular, when using a cell with #DIV/0! as argument, isNumeric(#DIV/0!)returns TRUE whereas ISNUMBER(#DIV/0!) returns FALSE. I want the latter behavior.

The behavior I want is:

  • True if a number e.g. "3" or "3.1415"
  • False if the content is a string e.g. "hello"
  • False if it is a LO Calc error e.g. "Error: 510"
  • False if mathematical errors e.g. "#N/A!" or "#DIV/0!" (that's the difficult part! See paragraph below…)

Eventually, regardless of my current problem (how to call the ISNUMBER() function), I would (also ;) ) love a general answer that could give a general procedure as to how to call LibreOffice Calc functions from the implementation of a LibreOffice Basic function.

Thanks in advance for your answers ;)