Loading Libraries

I am stumped by this! I am trying to run the ‘ggCalendar’ extension, and this part of the module is failing with a ‘NoSuchElement’ exception

'** Load Dlg_DatePicker
GlobalScope.BasicLibraries.loadLibrary(“My Macros & Dialogs”)
oCalDlg = LoadDialog(ggCalendar, Dlg_DatePicker)

This is the tree for my Dialogs

Libre Office Dialogs
MyDialogs
ggCalendar
Standard

and the ‘Libraries’ tab brings up
My Macros & Dialogs

I have looked at Andrew P and the documentation and cannot see what I should be doing…

Are you referring to the LoadDialog from the ModuleControl from the Tools library? In this case, you need to loadLibrary exactly the “Tools” library

GlobalScope.BasicLibraries.loadLibrary("Tools")

Also, pay attention to the parameter types:

Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)

Both first parameters are strings, perhaps you meant to write
oCalDlg = LoadDialog("ggCalendar", "Dlg_DatePicker")

1 Like

Just like the Basic language itself, the hierarchy of Basic containers, libraries and modules is difficult to understand.

The containers [LibreOffice Macros] and [My Macros] are GlobalScope, the union of all publicly accessible Basic libraries.
[LibreOffice Macros] resides read-only in the installation directory accessible to all users of the local machine, whereas [My Macros] resides in the user profile. [My Macros] is the place where the logged in user can read and write his own coding. Putting the rule to the test: Try to add a new library named “Tools” to [My Macros] fails because a library with that name exists in the same name space but under [LibreOffice Macros]. Use some other name such as “MyTools” for your own tools in [My Macros]
You load any of these libraries with GlobalScope.BasicLibraries.loadLibrary(sLibName).
Basic libraries that are embedded in documents have their own name space within each document. You load them without GlobalScope like this:

Sub Main
REM load Library1 embedded in ThisComponent and execute Main on Module1
ThisComponent.BasicLibraries.loadLibrary("Library1")
Library1.Module1.Main
End Sub

You do not have to load any library explicitly when Library1.Module1.Main is triggered by some script event, push button, toolbar etc. All these UI elements load libaries as needed. You only need to call loadLibrary(sLibName) when your code calls a library that is not yet loaded like the above example does.

The special library named “Standard” is loaded with the containing document. [My Macros].Standard is loaded with the office suite. “Standard” is a scratch pad for experimental code. Any code you may want to export to some other office installation via reference or via extension package should be stored in a library other than “Standard” unless you are willing to transfer code by means of copy&paste.

2 Likes

John - my apologies - there were “” in that bracket - it was the typing onto this forum that went wrong!

The error is triggering at the first line - GlobalScope.BasicLibraries.loadLibrary(“My Macros & Dialogs”)

It is getting that line right that is causing me the problem!

In that case, perhaps you want something like this?

GlobalScope.BasicLibraries.loadLibrary("ggCalendar")
ggCalendar.Calendar.DatePickerOpenSelCell

John - that is not working. I’ll abandon the extension for now, but thanks.

I don’t understand what could go wrong

run_ggCalendar

Nor me, John. I can see it running on your post, but if I place
GlobalScope.BasicLibraries.loadLibrary(“ggCalendar”)

in my basic macro I get ‘Syntax Error’

Is it to do with my original post?

"This is the tree for my Dialogs

Libre Office Dialogs
MyDialogs
ggCalendar
Standard

and the ‘Libraries’ tab brings up
My Macros & Dialogs"

The Tree in Text it is difficult to understand. Does it look like this?
dlgTree

Diaiogs

And you write that the code does nothing for you? Kindly check the macro in this spreadsheet - Loading Libraries (ggCalendar).ods (11.1 KB)

And please don’t post AS QUESTION ANSWERS - it will confuse future readers of this discussion. Use a comment.
Comment

Or we can transfer further discussion to a private chat (there is such an opportunity here)

SendMessage

Sorry, guys. I have no option for ‘Comment’ when I visit the topic, only ‘Suggest a solution’. Something weird has happened to my login.

Yes, John, that works as a sub but not as a line of code in ‘main’.

I am quite out of my depth here on the ‘library’ issue so I would prefer to leave the question. Thanks again for help to both.