using user-defined basic library in a calc document

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
regina
Posts: 67
Joined: Sat Apr 05, 2008 4:55 pm

using user-defined basic library in a calc document

Post by regina »

Hi,

I've got a basic macro library "gammatest" which has the modules "Distributions", "gamma" and "igamma". The modules contain several functions, for example a MYGAMMA(..).
This library is inside a document. In the "Standard"-library of the document there is the macro

Code: Select all

Sub Main
If NOT BasicLibraries.isLibraryLoaded("gammatest") Then
BasicLibraries.LoadLibrary("gammatest")
End If
End Sub
This macro is assigned to the event "OpenDocument". I can see that the library "gammatest" is loaded. When I newly use the function "=MYGAMMA(..)" in a cell, all works as expected. But when I close and reload the document, the cell shows a "'NAME?" error. If I enter edit mode, add or remove a space and confirm, the function will work again.

What have I to do, that the functions work immediately after opening the document? I do not want to move them to the "Standard" library, because from there I cannot export them. Does exist something like a "refresh"? An "Update all" does not work.

kind regards
Regina
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: using user-defined basic library in a calc document

Post by Villeroy »

Sheet functions need to be in a Basic-library "Standard" if they are not packaged as add-in. However, Basic add-ins are impossible since you can not implement classes in Basic.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
regina
Posts: 67
Joined: Sat Apr 05, 2008 4:55 pm

Re: using user-defined basic library in a calc document

Post by regina »

Is there really no way to make them work after reloading the document as they work when newly entered?
Why are the functions not found although the library is loaded? Is this a bug or a missing feature?
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: using user-defined basic library in a calc document

Post by Villeroy »

I'd say this is how it is implemented.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
uros
Volunteer
Posts: 30
Joined: Sun Dec 02, 2007 10:26 pm
Location: Slovenia

Re: using user-defined basic library in a calc document

Post by uros »

Hi Regina!
There is a way, clumsy but it works.
In Standard library add functions which calls each function in other modules. They must have different name, let's say original function name with underscore added.

Example (I don't know gamma functions...):

Library "Standard":

Code: Select all

Sub Main
If NOT BasicLibraries.isLibraryLoaded("gammatest") Then
BasicLibraries.LoadLibrary("gammatest")
End If
End Sub
'----------
Function _testsum (A As Integer, B As Integer) As Integer
     _testsum = testsum(A,B)
End Function
Library "gammatest":

Code: Select all

Function testsum (A As Integer, B As Integer) As Integer
     testsum = A + B
End Function
Now use "_functions" in your sheet cells...
Uros
Post Reply