Table Of ContentOpenOffice.org 3.1
BASIC Guide
Copyright
This document is published under the PDL. See: http://www.openoffice.org/licenses/
PDL.html
Contents
Copyright........................................................................................................................2
Preface.......................................................................................9
1 OpenOffice.org BASIC Programming Guide..................................11
2 The Language of OpenOffice.org BASIC.......................................15
Program Lines .............................................................................................................16
Comments ...................................................................................................................17
Markers .......................................................................................................................17
Implicit Variable Declaration ........................................................................................18
Explicit Variable Declaration ........................................................................................19
From a Set of ASCII Characters to Unicode.................................................................20
String Variables............................................................................................................21
Specification of Explicit Strings....................................................................................22
Integer Variables .........................................................................................................22
Long Integer Variables ................................................................................................23
Single Variables ..........................................................................................................23
Double Variables .........................................................................................................23
Currency Variables ......................................................................................................24
Floats ..........................................................................................................................24
Specification of Explicit Numbers ................................................................................24
Defining Arrays ............................................................................................................27
Defining values for arrays ...........................................................................................30
Accessing Arrays ........................................................................................................31
Array Creation, value assignment and access example ..............................................31
3
Local Variables ............................................................................................................31
Public Domain Variables .............................................................................................32
Global Variables ..........................................................................................................33
Private Variables .........................................................................................................33
Defining Constants ......................................................................................................34
Scope of Constants .....................................................................................................34
Predefined Constants ..................................................................................................34
Mathematical Operators ..............................................................................................35
Logical Operators ........................................................................................................35
Comparison Operators ................................................................................................36
If...Then...Else..............................................................................................................36
Select...Case................................................................................................................37
For...Next.....................................................................................................................39
For Each......................................................................................................................39
Do...Loop.....................................................................................................................40
While...Wend................................................................................................................41
Programming Example: Sorting With Embedded Loops .............................................41
Procedures ..................................................................................................................42
Functions ....................................................................................................................43
Terminating Procedures and Functions Prematurely ..................................................44
Passing Parameters ....................................................................................................44
Optional Parameters ...................................................................................................45
Recursion ....................................................................................................................46
The On Error Instruction ..............................................................................................47
The Resume Command ..............................................................................................47
Queries Regarding Error Information ..........................................................................48
Tips for Structured Error Handling ...............................................................................48
Type...End Type...........................................................................................................50
With...End With............................................................................................................51
3 The Runtime Library of OpenOffice.org Basic..............................55
Implicit and Explicit Type Conversions ........................................................................56
Checking the Content of Variables ..............................................................................58
Working with Sets of Characters .................................................................................60
Accessing Parts of a String .........................................................................................60
Search and Replace ...................................................................................................61
Formatting Strings .......................................................................................................62
Specification of Date and Time Details within the Program Code ...............................64
Extracting Date and Time Details ................................................................................65
Retrieving System Date and Time ...............................................................................66
Administering Files ......................................................................................................67
Writing and Reading Text Files ....................................................................................71
Displaying Messages ..................................................................................................74
Input Box For Querying Simple Strings .......................................................................75
Beep ............................................................................................................................76
Shell ............................................................................................................................76
Wait and WaitUntil .......................................................................................................77
Environ ........................................................................................................................77
4 Introduction to the API...............................................................79
Properties ....................................................................................................................81
Methods ......................................................................................................................81
The supportsService Method ......................................................................................83
Debug Properties ........................................................................................................83
API Reference .............................................................................................................84
Creating Context-Dependent Objects .........................................................................84
Named Access to Subordinate Objects .......................................................................85
Index-Based Access to Subordinate Objects ..............................................................87
Iterative Access to Subordinate Objects ......................................................................88
5 Working with OpenOffice.org Documents....................................89
ThisComponent ...........................................................................................................90
Basic Information about Documents in OpenOffice.org ..............................................91
Creating, Opening and Importing Documents .............................................................92
Document Objects ......................................................................................................95
Details about various formatting options ...................................................................100
6 Text Documents.......................................................................103
Paragraphs and Paragraph Portions .........................................................................104
The TextCursor ..........................................................................................................113
Searching for Text Portions .......................................................................................118
Replacing Text Portions ............................................................................................121
Tables ........................................................................................................................123
Text Frames ..............................................................................................................128
Text Fields .................................................................................................................131
Bookmarks ................................................................................................................135
7 Spreadsheet Documents...........................................................137
Spreadsheets ............................................................................................................138
Rows and Columns....................................................................................................139
Cells and Ranges.......................................................................................................141
Formatting Spreadsheet Documents.........................................................................147
Cell Ranges ..............................................................................................................161
Searching and Replacing Cell Contents ....................................................................164
8 Drawings and Presentations.....................................................167
Pages ........................................................................................................................168
Elementary Properties of Drawing Objects ...............................................................169
An Overview of Various Drawing Objects ..................................................................180
Grouping Objects ......................................................................................................187
Rotating and Shearing Drawing Objects ...................................................................189
Searching and Replacing ..........................................................................................190
Working With Presentations ......................................................................................191
9 Charts (Diagrams)....................................................................193
Title, Subtitle and Legend .........................................................................................195
Background ...............................................................................................................197
Diagram ....................................................................................................................197
Wall and Floor ...........................................................................................................198
Axes ..........................................................................................................................199
Properties of Axes .....................................................................................................200
Grids .........................................................................................................................203
Axes Title ..................................................................................................................204
3D Charts ..................................................................................................................206
Stacked Charts .........................................................................................................207
Line Charts ................................................................................................................208
Area Charts ...............................................................................................................208
Bar Charts .................................................................................................................209
Pie Charts .................................................................................................................209
10Databases...............................................................................211
Queries .....................................................................................................................214
Iteration of Tables ......................................................................................................217
Type-Specific Methods for Retrieving Values ............................................................218
The ResultSet Variants .............................................................................................219
Methods for Navigation in ResultSets .......................................................................220
Modifying Data Records ............................................................................................221
11Dialogs....................................................................................223
Creating Dialogs .......................................................................................................223
Closing Dialogs .........................................................................................................226
Access to Individual Control Elements ......................................................................227
Working With the Model of Dialogs and Control Elements ........................................227
Name and Title ..........................................................................................................228
Position and Size ......................................................................................................228
Focus and Tabulator Sequence ................................................................................229
Multi-Page Dialogs ....................................................................................................230
Parameters ...............................................................................................................236
Mouse Events ...........................................................................................................237
Keyboard Events .......................................................................................................239
Focus Events ............................................................................................................240
Control Element-Specific Events ...............................................................................241
Buttons ......................................................................................................................242
Option Buttons ..........................................................................................................243
Checkboxes ..............................................................................................................244
Text Fields .................................................................................................................245
List Boxes .................................................................................................................248
12Forms......................................................................................251
Determining Object Forms ........................................................................................252
The Three Aspects of a Control Element Form .........................................................253
Accessing the Model of Control Element Forms .......................................................253
Accessing the View of Control Element Forms .........................................................254
Accessing the Shape Object of Control Element Forms ...........................................255
Buttons ......................................................................................................................256
Option Buttons ..........................................................................................................258
Checkboxes ..............................................................................................................260
Text Fields .................................................................................................................261
List Boxes .................................................................................................................263
Tables ........................................................................................................................266
Preface
This guide provides an introduction to programming with OpenOffice.org Basic. To
get the most out of this book, you should be familiar with other programming
languages. Extensive examples are provided to help you quickly develop your own
OpenOffice.org Basic programs.
Note – Throughout this document, the OpenOffice.org installation directory is
represented in syntax as install-dir.
9
1
C H A P T E R 1
1 OpenOffice.org BASIC Programming
Guide
This guide divides information about OpenOffice.org administration into several
chapters. The first three chapters introduce you to OpenOffice.org Basic:
The Language of OpenOffice.org Basic
Runtime Library
Introduction to the API
These chapters provide an overview of OpenOffice.org Basic and should be read by
anyone who intends to write OpenOffice.org Basic programs. The remaining chapters
describe the individual components of the OpenOffice.org API in more detail and can
be read selectively as required:
Working with Documents
Text Documents
Spreadsheet Documents
Drawings and Presentations
Charts (Diagrams)
Databases
Dialogs
Forms
11
Description:Formatting Strings ..62 Specification of Date and Time Details within