In general, Basic does not look inside a container, such as an Object, to see what names might be defined there. The Goto ErrorHandler ensures that LibreOffice Basic exits the current program line and then executes the ErrorHandler: code. The Step property of a dialog defines the current tab page of the dialog whereas the Step property for a control element specifies the tab page where the control element is to be displayed. The As keyword syntax, and the fact that a comma is not used, goes back to the roots of the Basic language. As in text documents, drawing documents provide a function for searching and replace. In previous versions of the Basic Programming Guide these instructions were used to obtain the current document: This correct code has a drawback: it does not work if the macro is started from the IDE because it then refers to the IDE, not the document. For example, the following line declares an array with four integer variables: In the previous examples, the index for the array always begins with the standard start value of zero. The createTextCursorByRange call then creates a Cursor, which is positioned at the anchor position of the bookmark. The FileLen function determines the length of a file in bytes (as long integer value). In particular, if such a request is made by pressing the right mouse button on the control, the event will be fired twice: once for the popup menu request, and once for the real mouse event. The lengths are specified in hundredths of a millimeter. The simplest scenario is for the button to trigger a When Initiating event when it is clicked by a user. The 0 (zero) used as the second parameter in the Dir function ensures that Dir only returns the names of files; directories are ignored. In other words, formatting using templates is assigned a lower priority than direct formatting in a text. Some DOS-specific properties are no longer used in functions that expect file properties as parameters (for example, to differentiate from concealed files and system files). Both interfaces provide you with an object, through which the properties for searching and replacing can be defined. The text fields found are checked for the service supported using the supportsService method. The cell objects are available through the getCellByName() method of the table object. "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. The syntax for label names is the same as for variable names. For a more detailed picture, see the API reference. The functionality can, however, be imitated by using the IsBoolean function: The IsBoolean function defines an internal Dummy help variable of the Boolean type and tries to assign this to the transferred value. The following example shows how these can be used in conjunction with a TextCursor. A long integer variable can take up to four bytes of memory. The type is declared in the same way as a variable declaration: If the return type is not specified (see first example of this page), the function returns a variant. placeholders in both VBA and LibreOffice Basic. libreoffice basic programming guide pdf By July 27, 2021 OpenOffice Basic . The interpreter, which is needed to run LibreOffice Basic macros. Note: The com.sun.star.presentation.PresentationDocument service, responsible for presentation documents, also provides the complete com.sun.star.drawing.DrawingDocument service. Even though you can use these procedures in any module, it is best to limit their use to two modules. All the above debug tools work on a running program. Mathematical operators can be applied to all numbers types, whereas the + operator can also be used to concatenate strings. If nothing is assigned, the function returns a zero value (number 0 for numerical values and a blank for strings). When using the ResultSet's UPDATEABLE and SCROLL_SENSITIVE properties, the scope of function of a ResultSet is comparable with a Dynaset type Recordset from ADO and DAO. If there is another line inwards, it marks the transition to a filled area. All occurrences of the name, The character $ marks a paragraph end. If the PushButtonType has the value of 2, the dialog is closed and the Execute method of the dialog returns the value 0 (dialog closed). The command: specifies a delay of 2 seconds (2000 milliseconds). XIndexContainer provides methods for inserting and removing elements. This chapter provides a background on the API. In this guide, a table-based document or spreadsheet document is the entire document, whereas a spreadsheet (or sheet for short) is a sheet (table) in the document. If you want to use an external bitmap file, you can specify its URL in the FillBitmapURL property. Buy a printed copy. The easiest way to change a variable from one type to another is to use an assignment. VBA: The rules for constructing markers are different in LibreOffice Basic than in VBA. return the number of pages, words, or characters of a text. The computer saves the strings internally as a sequence of numbers where each number represents one specific character. Global variables are declared in the header section of a module using the keyword Global: Private variables are only available in the module in which they are defined. In the strictest sense of the word, a service in UNO does not support methods, but rather interfaces, which in turn provide different methods. A, on the other hand, is a string, and the computer saves a one- or two-byte long value for each character (each number). When working with the indexes, note that getCount returns the number of elements. This example shows how you may define and use a struct, and how to reference the items within it, both with and without With. The createInstance method, which is defined in the XMultiServiceFactory interface, is used in particular in the document objects. The queries are accessed by means of the QueryDefinitions method of the data source. Such objects and services are also known as context-independent services. This method deletes the range that is defined in the CellRangeAddress structure from the sheet. LibreOffice also supports complex polygonal shapes through the com.sun.star.drawing.PolyPolygonShape service. The view of the control element can then be determined with the assistance of the model and using the document controller. The name StarDesktop was, however, retained for the frame object of LibreOffice because it clearly indicates that this is a basic object for the entire application. The formatting properties can be found in each object (Paragraph, TextCursor, and so on) and can be applied directly. Among the most useful are: LibreOffice Basic understands common mathematical, logical, and comparison operators. its spell checker, forms designer, and charting tools). Purchase or download the latest LibreOffice Calc Guide, written by community experts. The following properties define the horizontal and vertical justification of a text: The following example shows how you can "stack" the contents of a cell so that the individual characters are printed one under another in the top left corner of the cell. The characters are not rotated. The assignment does not need to be placed at the end of the function, but can be made anywhere in the function. LibreOffice Basic then interprets the following line as a regular instruction again. which at first glance seems straightforward, ultimately proves to be something of a trap. The argument of the method is the position, counted from 0, of the existing page after which the new page will be inserted. The page properties that are valid for both types of documents are defined in the com.sun.star.style.PageProperties service. This example shows how to connect to an existing data source. The functions for writing the HTML file, as well as a test code that checks the font weight of the corresponding text portions and provides paragraph portions in bold type with a corresponding HTML tag, have been added. It is described in the chapter Apache OpenOffice Basic of the Developer's Guide. The Select command is not restricted to simple 1:1 assignments you can also specify comparison operators or lists of expressions in a Case branch. VBA: Text frames are LibreOffice's counterpart to the position frame used in Word. Variables that are declared in a function or a procedure are called local variables: Local variables only remain valid as long as the function or the procedure is executing, and then are reset to zero. The Basic interpreter's line-oriented execution produces one of the key differences between Basic and other programming languages. Throughout this document, the LibreOffice installation directory is represented in syntax as install-dir. Styles are named lists containing formatting attributes. Both the X and Y-axes have a gray grid for visual orientation. The call is made by entering the procedure name at the relevant point of the program. The previous example may change the text as requested, but it may sometimes also destroy the formatting. If you want to delete directory (including its files) use the RmDir function. Many of the styles that are described are also available for text documents. The cell type is not determined by the content that is saved in the cell, but rather the object property which was used for its entry. To display all information available from an object and link to the corresponding API documentation, use instead the Development Tools built into LibreOffice or MRI extension. The & operator is safer when dealing with strings because it assumes that all arguments should be strings, and converts the arguments to strings if they are not strings. Parameters are normally passed by Reference in LibreOffice Basic. LibreOffice Basic libraries contain classes, routines and variables, Python modules contain classes, functions and variables. LibreOffice notes the SQL commands of queries so that they are available at all times. If you want to find other matches for the string, the function also provides the opportunity to specify an optional start position from which LibreOffice Basic begins the search. The simplest variant is a single-color fill. For all axes an additional title can be displayed. These variables are available to all the modules in their library: The value of variable A is not changed by the Test function, but is increased by one in the Flip function and decreased by one in the Flop function. The XIndexAccess and XIndexContainer interfaces are used in objects which contain subordinate objects and which can be addressed using an index. The parameter provides the option of adding additional buttons, defining the pre-assigned button, and adding an information symbol. These are useful if no cells have been merged in the table. Bar charts (com.sun.star.chart.BarDiagram) support two X-axes, two Y-axes and one Z-axis. Instead of producing an error message, the interpreter initializes the typing error as a new variable with a value of 0. They can be displayed as 2D or 3D graphics (com.sun.star.chart.Dim3DDiagram service). These are available through the Rows and Columns properties of the spreadsheet object and support the com.sun.star.table.TableColumns and/or com.sun.star.table.TableRows services. The following example also shows a correct declaration, but with negative data field limits: It declares an integer data field with 6 values that can be addressed using the indexes -10 to -5. A SearchDescriptor is an object which supports the com.sun.star.util. Others use standard interfaces such as JDBC or ODBC. A table consists of individual rows. The paragraph properties are available through the com.sun.star.style.ParagraphProperties service. When Var is 0, there is a match. The runtime library: Provides standard functions which have no direct reference to LibreOffice, for example, functions for editing numbers, strings, date values, and files. For example, the TextCursor in the following example. Functions and procedures can receive one or more parameters. The declaration can only be made using the supplement As Date. Note: You can access individual pages either through their number or their name. LibreOffice automatically ensures that the relevant data is retrieved from the database, and that any changes made are written back to the database. As of LibreOffice Version 3.3, this status does not show in the GUI, nor is there any GUI way to re-enable the feature. VBA: Unlike VBA, LibreOffice Basic ensures that the name of a local variable is not used simultaneously as a global and a private variable in the module header. Note: LibreOffice forms may contain text fields, list boxes, radio buttons, and a range of other control elements, which are inserted directly in a text or spreadsheet. If this is the case, the Control.Name property then checks whether the name of the control element is MyListBox. The following call, for example, determines whether the TextElement object supports the com.sun.star.text.Paragraph service. This book introduces Base, the database component of LibreOffice. The type declaration symbol is #. The method getTextTables() of the text document object is used for this purpose: Note: In the following example, both module A and B have a Private variable called C. The Test function first sets the Private variable in module A and then the Private variable in module B. The Print method of the com.sun.star.view.Xprintable interface is provided for this purpose. Forms are created using the Form Controls and the Form Design Toolbar directly within the document. For example, if only the C:\SubDir1 directory exists, then a call. The Format Cells dialog in LibreOffice Calc provides an overview of the different formatting options for cells. Dialogs can, for example, display database information or guide users through a step-by-step process of creating a new document in the form of a Wizard. storeAsURL provides the following options: The following example shows how the Overwrite option can be used in conjunction with storeAsURL: The example then saves Doc under the specified file name if a file already exists under the name. However, the names are not case-sensitive. You can also pass a parameter as a value if you do not want subsequent changes to the parameter to affect the value that is originally passed. It contains the following properties: The following example uses the KeyCode property to establish if the Enter key, the Tab key, or one of the other control keys has been pressed. LibreOffice provides a programming interface in the form of the Universal Network Objects (UNO). An example of how to use the definition, and how to reference the fields within an instance, appears in the section on WithEnd With. All properties form part of the associated model objects. Since LibreOffice is a platform-independent application, it uses URL notation (which is independent of any operating system), as defined in the Internet Standard RFC 1738 for file names. As Basic makes automatic type conversions, there is usually no problems using a constant in an expression. When working with spreadsheets, an intermediate stage is needed for the Sheets list because the drawing levels are not located directly in the document but in the individual sheets: As is already suggested by the GetByIndex method name, a document may contain several forms. LibreOffice provides various functions that allow you to change the justification of a text in a table cell. Some UNO services in turn support other services so that, through one object, you are provided with a whole range of services. The previous example creates a bar chart. Even in the standard installation, LibreOffice Basic has all the components needed to create its own Basic macros, including: The components of the LibreOffice API that are discussed in this guide were selected based on their practical benefits for the LibreOffice Basic programmer. 257x267pxThe LibreOffice Basic development environment. Note: The counter is incremented by 1 at the end of each pass. VBA: Other limit values sometimes apply for data field indexes in VBA. In the preceding example, you can also assign the Step value of 0 to the dividing line as well as the Cancel, Prev, Next, and Done buttons to display these elements on all pages. Set focus. The following example creates a table with the help of the createInstance method described previously. The Map AppFont (ma) replaces the Twips unit to achieve better platform independence. Any existing values in the specified cell range are moved below the range. The code in the following example moves an entry from the left to the right list box of a dialog. If the center of a paragraph, for example, contains a word printed in bold, then it will be represented in LibreOffice by three paragraph portions: the portion before the bold type, then the word in bold, and finally the portion after the bold type, which is again depicted as normal. LibreOffice Basic recognizes but ignores this keyword, because this is already the default procedure in LibreOffice Basic. The corresponding constant for SearchFlags is: The following example shows how the content of an opened window can be replaced with the help of the frame parameter and SearchFlags: The example first opens the test.odt file in a new window with the frame name of MyFrame. If you start the macro from the IDE, ThisComponent will still find and return your document. Once the writing process has been completed, the file must be closed using a Close call: Again here, the file handle should be specified. The data field must provide a PropertyValue structure for each option in which the name of the option is saved as a string as well as the associated value. The Internet Standard RFC 1738, upon which this is based, permits use of the 0-9, a-z, and A-Z characters. When you select a name for a marker, the following rules apply: There is, however, one exception to this rule: a distinction is made between uppercase and lowercase characters for UNO-API constants. If you assign a floating point number to a long integer variable, the number is rounded up or down to the next whole number. These are defined in the com.sun.star.text.TextTable service. The following values are available: The following example creates a circular slice with a 70 degree angle (produced from difference between start angle of 20 degrees and end angle of 90 degrees). Example declaration of a Boolean variable: Date variables can contain date and time values. The API can be used not only by LibreOffice Basic, but also by other programming languages, such as Java and C++. There is no direct counterpart in LibreOffice Basic for the Characters, Sentences and Words lists provided in VBA. Upon closer inspection, the following code sequence. Whereas the dialog functions are available in all LibreOffice documents, the full scope of the form functions are only available in text and spreadsheets. If you do have such collision, Basic may produce strange runtime error messages, or your Sub may not work. The following example sets the page size of a drawing document which has just been opened to 20 x 20 centimeters with a page margin of 0.5 centimeters: Warning: What is written here also applies to Impress documents. Extensive examples are provided to help you quickly develop your own LibreOffice Basic programs. Note: Character objects in UNO, for example, provide the getPosition and setPosition methods through which the associated key point can be called up and changed. The interface com.sun.star.sheet.Spreadsheets provides a better method to create a new sheet: insertNewByName. These may be outside the flow of text and can be positioned anywhere on the page. The InteractionHandler ensures that LibreOffice asks the user for the required login data. Direct formatting is used in particular with short documents because the formats can be assigned by the user with the mouse. VBA: The method for passing parameters to procedures and functions in LibreOffice Basic is virtually identical to that in VBA. The methods are accessed through the following object call: A format is specified using a format string that is structured in a similar way to the format function of LibreOffice Basic. AnchorType receives the AS_CHARACTER value. You can design each page separately. The updateString method, for example, allows a string to be written. Care should be taken when you use the On Error Resume Next command as this dismisses all open error messages. For more information about the LibreOffice API and the Software Development Kit, visit https://api.libreoffice.org. These are presented in detail in the #Introduction to the LibreOffice API. However, this call does not affect the UNO sequences that are defined through the LibreOffice API whose index always begins with 0. In addition to the Yes and No states, a check box can have an in-between state if the corresponding Yes or No status has more than one meaning or is unclear. The same applies when attempting to assign a string to a Boolean variable: Again, the basic interpreter reports an error. You will find a range of examples which use these methods in the following sections. To define the cell range that you want to insert, use the com.sun.star.table.CellRangeAddress structure. If you are familiar with an interface, then you can transfer your knowledge from one service to another.