LibORef no1

LibreOffice RefCard

Object Catalog

LibreOfice Basic

Displays the 3 containers types and their contents: libraries, modules and macros.

IDEv. 1.05 – 01/15/2019

Containers My Macros & Dialogs

Beginner

Writen using LibreOffice v. 5.3.3 – Platform: All☞ IDE : Integrated development environment.
A set of tools for writing and debugging your macros code.

Getting To The IDE
Menu Tools > Macros > Organize macros > LibreOffice Basic ( Alt + F11 ) then select the desired module to edit (Edit button).

Specific to the user’s account, for all documents. Can
only be used by the user.

LibreOffice Macros & Dialogs(aka global macros)
These macros are stored within the LibreOffice globalcontainer. As such, they can be viewed and used everywhere.
The ones on the capture are part of a standard
LibreOffice install.

Untitled 1 (in the example)
In the current document.

Overview

Libraries
Loaded (colored)  or not (grayed-out) .

Standard Library
Apart from global libraries, each container comes with a Standard library.
☞ Standard is always loaded at opening time (of the application or the document):
It can’t be deleted.
It can’t be overwritten through some code import.
It can’t be encrypted.

Modules 
Subprograms (macros) Code Editor
Used for code writing (with syntax highlighting) and debugging(read on).

The IDE window is made of 10 tools, most of them are described in this refcard.
Name of the container and of the current library.
➊ Title bar
Standard LibreOffice menus, dedicated to macros➋ Menu Barmanagement.
The LibreOffice Standard toolbar, showing only tools➌ Standard toolbar
dedicated to code edition and debugging.
Tools dedicated to code edition and debugging.
➍ Macros toolbar
Containers tree-view showing libraries, modules and➎ Object catalog
subprograms.
Main area for code edition, with syntax highlighting,➏ Code editor
breakpoints management and execution control.
Variable contents checking (watches).
➐ Watch pane
Subprogram calls and their parameters.
➑ Call stack panel
Lists and manages the current library modules.
➒ Tab bar
Run-time status.
➓ Status bar
 The main panels (Catalog ➎, Editor ➏, Watches ➐ and Call stack ➑) can be detached.
 F6 swaps from a tool to the next one.

Useful Items In the Edition Panel➊ Gutter
A “margin” in which the breakpoints ➍ and the execution flag
➎ are displayed.
➋ Line numbers
For easier navigation (toggled using View > Line Numbers).
➌ Editor
Helps writing Basic code. Supports syntax highlighting.
(Un)Indenting lines
Press Tab / Maj + Tab to indent/unindent lines of code.
☞ These commands can be used when selecting a set of lines.

Syntax Highlighting
The colors used are specified in LibreOffice options: Tools > Options > LibreOffice > Application Colors. Check the Basic Syntax Highlighting section values.

Displaying/hiding line numbers

Toolbars

Toggle line numbers display with View > Line Numbers.
☞ You may add a button to the Macros toolbar (see Category BASIC).
☞ Breakpoint management and execution control: see Debugging.

If not visible : View > Toolbars.

Goto Line

Standard Toolbar

Ctrl + L

Two toolbuttons are of interest:

Watches Panel

Select macro
Modules

Calls the macro selection dialog.
Calls the Macros Organizer dialog.

Macros Toolbar
Library selector« Compile »Run immediately F5Stop Maj + F5
Step Over Maj + F8
Step Into F8Step Out Ctrl + Maj + F8
Breakpoint On/off F9Manage Breakpoints
Enable Watch F7
Find Parenthesis
Import Basic
Export Basic
Import Dialog

Selection of the library to use.
Syntax checking.
Run the subprogram under the cursor.
Stop the running program.
Step-by-step execution, bypassing the called.
Step into the called subprogram.
Step out to the caller.
(De)activate the breakpoint on current line.
Opens the breakpoints dialog.
Adds the selected var to the watches.
Import a macro source code.
Save the source code (macro or dialog).
Import a dialog source code.

Dialog Toolbar
This toolbar takes place of the Macros toolbar when editing dialog boxes.
Insert Controls
Same contents as the controls toolbar (below).
Import a dialog box source code.
Import Dialog
Export Dialog
Export a dialog box source code.
The files have a .xdl extension (XML).

Controls Toolbar
This toolbar is shown when in dialog box conception mode. It displays each available control to place on a dialog. These three buttons deserve an explanation:
Select Element
Get back to selection mode.
Manage Language
Multilingual dialog creation.
Preview Dialog
Dialog test mode (hit Esc to get back to edition mode).
LibOBasic_01_IDE_Flat_A4_EN_v105.odt

Allows checking variable contents at runtime (more in Debugging below).
Three columns (adjustable widths):• Variable name• Value• Type

Adding A Watch
1. In the code, select the variable to observe (you may enter its name in the Watch zone),
2. click the Enable Watch button
F7 .

Removing A Watch
1. Select the watch to remove,
2. click Remove Watch(in the Watches panel)

Call Stack PanelIn step-by-step execution mode, allows to know thesuccessive subprograms calls.
Read it bottom-up. All subprograms are listed
along with their parameter values.
Subprogram 0 is the one in which the execution iscurrently. The others are numbered subsequently.

Tab BarHints

Displays the modules names for the current library.
Modules names are shown in alphabetical order, leftto right.

Copying A Library Between Containers

Right-click on the bar to manage the modules:
Insert > Basic Module
Create a new code module (defaults to ModuleN).
Insert > Basic Dialog
Create a new dialog module (defaults to DialogN).
DeleteDelete the selected module.
RenameRename the selected module.
Hide
Temporarily hide the selected module.
Modules
Calls the Macro Organizer.

1. Open the source document/container,
2. Open the Macro Organizer ( ), Libraries tab,
3. Select the library Location,
4. Export > Export as Basic library,
5. Open the target document/container,
6. Import.

Copying Modules From A Library To Another(in the same document or between documents/containers)
1. Open both source and target documents/containers,
2. Open the Macro Organizer ( ),3. Drag/drop from source to target.
 By default, modules are moved. To copy: Ctrl + drag/drop.

Status Bar

Hiding Modules

From let to right:• The subprogram full name in which the cursor currently sits.
• The current code edition mode (switch to Overwrite using Ins ).
• The line (Ln) and column (Col) (character) number where the cursor currently is.

Allows to (temporarily) simplify the tab row: right-click a tab then > Hide.

Debugging
Debugging: checking a program execution.
☞ This operation is realized executing the program part to be checked in step-by-stepmode while watching the execution context (variables values).
Debugging uses three panels: code editor ➏, call stack ➐ and watch pane ➑. It runs under the control of the three step-by-step buttons (Macros toolbar ➍) and breakpoints.

Encrypting Libraries
Encrypting a library makes a more secure code.
☞ Any library may be encrypted, except Standard.
1. Open the Macro Organizer ( ), Libraries tab,
2. Select the Location,
3. Select the library,
4. Click Password,
5. Enter the New password and confirm,
6. Validate.
 Warning!
The encryption is very strong (AES): password loss is irremediable!
☞ Always keep a non-encrypted version for yourself.

Cleaning MSOffice imports
Delete the unnecessary libraries and modules that came with the import.
 Always work on a copy of your file!
1. Save to the “flat” format (ex: .fods)
2. Open the “flat” file using a XML-capable text editor.
3. Search for the <office:scripts> markup.
4. Delete the whole section between (including) the <ooo:library-embedded
ooo:name="Standard"> and </ooo:library-embedded> marks.
5. Save.
6. Open with LibO and re-create the correct libraries/modules tree (copy/paste the wanted
code from the original document to the current one).

Execution Modes
Five buttons define the way the code is run. The
mark displays the execution point.
☞ Note that when you start execution (any mode) while the cursor is in a subprogram that
requires non-optional parameters, you get an error message: Argument is not optional.
Run Maj + F5
Runs the subprogram where the cursor sits. The execution stops at breakpoints only.
Stop F5
Stops the execution.
Step Over Maj + F8
Step-by-step execution without entering the subprograms.
Step Into F8
Step in subprograms.
Step Out Ctrl + Maj + F8
Step out to callers.

IDE Keyboard Shortcuts
Macros dialog
Goto line
Add/remove breakpoint
Activate a watch
Immediate execution

Alt + F11
Ctrl + L
F9F7
Maj + F5

Stop execution
Step Over
Step Into
Step Out
Switch IDE tool

F5
Maj + F8
F8Ctrl + Maj + F8
F6Managing Breakpoints
Breakpoint: a mark where the execution is paused. This allows to examine the execution
context at that moment (watches values).
Execution is paused before executing the marked line.
☞ The actions below may be accomplished during a debugging session.

Adding A Breakpoint
Double-click in the gutter on the line to stop at when no breakpoint exists ( F9 ).

Deleting A Breakpoint
Double-click in the gutter on an existing breakpoint( F9 ).

Disabling/Re-enabling A Breakpoint
Right-click in the gutter on any existing breakpoint,then disable Active. The icon turns from(active)
to(inactive).

Breakpoints Manager
Call it by:• right-clicking the execution mark or any existing
breakpoint, option Properties• clicking the Manage Breakpoints button. Top to bottom:(list and edition area)
Line numbers where breakpoints are set.
Select or create a new one.
Active(Un)Check to (de)activate the selected breakpoint.
Pass Count
Activates a breakpoint after a given number of passes.
New
Click to add a new breakpoint on the specified line.
DeleteDeletes the selected breakpoint.

Options
LibreOffice offers a set of IDE options in Tools > Options > LibreOffice > Basic IDE☞ These options are available after having checked the Enable experimental features inCreditsAuthor : Jean-François Nifenecker – jean-francois.nifenecker@laposte.net
We are like dwarves perched on the shoulders of giants, and thus we are able to see more and farther than thelatter. And this is not at all because of the acuteness of our sight or the stature of our body, but because we arecarried aloft and elevated by the magnitude of the giants (Bernard de Chartres [attr.])History
Version

Date

1.04

09/10/2018

Minor updates

Comments

1.05

01/15/2019

Minor updates

Tools > Options > LibreOffice > Advanced
Enable code completion

Autocorrection
Autoclose quotes
Autoclose parenthesis
Autoclose procedures
UseExtended types

The IDE automatically completes the Basic objects methods☞ Doesn’t apply to custom objects.
☞ The UseExtended types option must be enabled.
Fixes keywords and variable names syntax.
When typing " (double quote), the IDE adds the closing quote.
When typing ( (parenthesis), the IDE adds the closing parenthesis.
When typing Sub Xxx or Function Xxx (Sub or Function declaration), the IDE adds an End Sub or End Function.
(needed to get code completion)
Allows using UNO object types as valid for Basic.

LicenseThis refcard is placed under theCreativeCommons BY-SA v4 (intl) license.
More information:
https://creativecommons.org/licenses/by-sa/4.0/