Page 1 of 1
[Solved] Call Calc doc. Basic Sub from getScript impossible?
Posted: Sun Feb 21, 2010 9:56 am
by gurfle
I have a Sub MakeNormCoinToss in a module called "RandomCode" in a Calc document called "Annex.ods", and this call to getScript
Code: Select all
getScript("vnd.sun.star.script:Annex.RandomCode.MakeNormCoinToss?language=Basic&location=document")
fails with the error
Code: Select all
The following Basic script could not be found:
library: 'Annex'
module: 'RandomCode'
method: 'MakeNormCoinToss'
location: 'document'
If, however, I move the Sub MakeNormCoinToss to the Tools module in the "My Macros" Standard Library I can get the same getscript call to complete successfully - of course after replacing "Annex.RandomCode" with "Standard.Tools" and "location=document" with "location=application".
Is it not possible to use getscript to start up a Basic Sub embedded in a document?
Re: Call of Basic Sub in Calc doc. from getScript impossible ??
Posted: Sun Feb 21, 2010 11:37 am
by Villeroy
Run this first:
Code: Select all
someDoc.BasicLibraries.loadLibrary("Annex")
Re: Call of Basic Sub in Calc doc. from getScript impossible ??
Posted: Sun Feb 21, 2010 11:28 pm
by gurfle
Thanks, Villeroy, for the suggestion

. Unfortunately it did not help.
Even though the code making the call to MakeNormCoinToss also resides in the same "Annex" document (in fact in the same "RandomCode" module), I really want to use getScript - instead of a straight Basic sub call - because the calling code needs to build the name of the sub to be called from string variables.
When I check (from Annex.ods) thiscomponent.BasicLibraries.ElementNames, "Annex" and "Standard" are listed.
I tried moving MakeNormCoinToss to a module in the "Standard" library of Annex.ods with no success either. Only by moving MakeNormCoinToss to the "My Macros" Standard.Tools module can I get it to run from getScript.
At least it sounds from your reply that what I am attempting ought to be possible, but I am out of ideas as to what I am doing wrong or where to search. As I said, I am trying everything from just one document.
Thanks, Nick
Re: Call of Basic Sub in Calc doc. from getScript impossible ??
Posted: Mon Feb 22, 2010 12:00 pm
by B Marcelly
Hi,
You did not show your not-working code
You must get the script provider from the document, not from the MasterScriptProviderFactory.
This is a working call (in Basic).
Code: Select all
Dim scriptPro As Object, myScript As Object
scriptPro = ThisComponent.getScriptProvider()
myScript = scriptPro.getScript("vnd.sun.star.script:Library1.Module1.Main?language=Basic&location=document")
myScript.invoke(Array(), Array(), Array() )
You don't need to load the library before calling the script.
Re: Call of Basic Sub in Calc doc. from getScript impossible ??
Posted: Tue Feb 23, 2010 5:21 am
by gurfle
B Marcelly wrote:Hi,
You did not show your not-working code
You must get the script provider from the document, not from the MasterScriptProviderFactory.
Indeed, you figured out what was wrong without even seeing my code
I had been extracting what seemed relevant pieces from the example at
http://www.oooforum.org/forum/viewtopic.phtml?t=59534:
Code: Select all
createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory").createScriptProvider("").getScript("vnd.sun.star.script:Annex.RandomCode.MakeNormCoinToss?language=Basic&location=document").invoke(arglist,Array(),Array())
but your correction not only works, but is a lot less ugly

:
Code: Select all
ThisComponent.getScriptProvider().getScript("vnd.sun.star.script:Annex.RandomCode.MakeNormCoinToss?language=Basic&location=document").invoke(arglist,Array(),Array())
Not quite sure yet about the subtle distinction between these alternatives, but having such interesting examples to ponder now should help me get it soon enough.
In the future I commit to making more effort at extricating key pieces of code to illustrate such hangups. Again,

to B Marcelly for seeing that the document script provider as opposed to the MasterScriptProviderFactory was the culprit.