Page 1 of 1

using user-defined basic library in a calc document

Posted: Sat Apr 05, 2008 6:17 pm
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

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

Posted: Sat Apr 05, 2008 7:19 pm
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.

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

Posted: Sat Apr 05, 2008 8:06 pm
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?

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

Posted: Sat Apr 05, 2008 8:28 pm
by Villeroy
I'd say this is how it is implemented.

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

Posted: Sun Apr 06, 2008 10:37 am
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