OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Overview of Central Interfaces 73<br />
For I = 0 to Sheets.getCount() - 1<br />
Sheet = Sheets.getByIndex(I)<br />
' Editing sheet<br />
Next I<br />
The example shows a loop that runs through all sheet elements one after another and saves<br />
a reference to each in the Sheet object variable. When working with the indexes, note that<br />
getCount returns the number of elements. The elements in getByIndex however are<br />
numbered beginning with 0. The counting variable of the loop therefore runs from 0 to<br />
getCount()-1.<br />
com. sun. star. container. XIndexContainer Interface<br />
The XIndexContainer interface provides the insertByIndex and removeByIndex functions.<br />
The parameters are structured in the same way as the corresponding functions in<br />
XNameContainer.<br />
Iterative Access to Subordinate Objects<br />
In some instances, an object may contain a list of subordinate objects that cannot be<br />
addressed by either a name or an index. In these situations, the XEnumeration and<br />
XenumerationAccess interfaces are appropriate. They provide a mechanism through which<br />
all subordinate elements of an objects can be passed, step by step, without having to use<br />
direct addressing.<br />
com. sun. star. container. XEnumeration and XenumerationAccess<br />
Interfaces<br />
The basic object must provide the XEnumerationAccess interface, which contains only a<br />
createEnumeration method. This returns an auxiliary object, which in turn provides the<br />
XEnumeration interface with the hasMoreElements and nextElement methods. Through<br />
these, you then have access to the subordinate objects.<br />
The following example steps through all the paragraphs of a text:<br />
Dim ParagraphEnumeration As Object<br />
Dim Paragraph As Object<br />
ParagraphEnumeration = Textdoc.Text.createEnumeration<br />
While ParagraphEnumeration.hasMoreElements()<br />
Paragraph = ParagraphEnumeration.nextElement()<br />
Wend<br />
The example first creates a ParagraphEnumeration auxiliary object. This gradually returns<br />
the individual paragraphs of the text in a loop. The loop is terminated as soon as the<br />
hasMoreElements method returns the False value, signaling that the end of the text has<br />
been reached.