OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
OpenOffice.org BASIC Guide - OpenOffice.org wiki
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Working With Forms<br />
The GetByIndex method returns the form with the index number 0.<br />
When working with spreadsheets, an intermediate stage is needed for the Sheets list because the drawing levels are<br />
not located directly in the document but in the individual sheets:<br />
Dim Doc As Object<br />
Dim Sheet As Object<br />
Dim DrawPage As Object<br />
Dim Form As Object<br />
Doc = ThisComponent<br />
Sheet = Doc.Sheets.GetByIndex(0)<br />
DrawPage = Sheet.DrawPage<br />
Form = DrawPage.Forms.GetByIndex(0)<br />
As is already suggested by the GetByIndex method name, a document may contain several forms. This is useful,<br />
for example, if the contents of different databases are displayed within one document, or if a 1:n database<br />
relationship is displayed within a form. The option of creating sub-forms is also provided for this purpose.<br />
The Three Aspects of a Control Element Form<br />
A control element of a form has three aspects:<br />
The Model of the control element is the key object for the <strong>OpenOffice</strong>.<strong>org</strong> Basic-programmer when working<br />
with control element forms.<br />
The counterpart to this is the View of the control element, which administers the display information.<br />
Since control element forms within the documents are administered like a special drawing element, there is<br />
also a Shape object which reflects the drawing element-specific properties of the control element (in<br />
particular its position and size).<br />
Accessing the Model of Control Element Forms<br />
The models of the control elements of a form are available through the GetByName method of the Object form:<br />
Dim Doc As Object<br />
Dim Form As Object<br />
Dim Ctl As Object<br />
Doc = ThisComponent<br />
Form = Doc.DrawPage.Forms.GetByIndex(0)<br />
Ctl = Form.getByName("MyListBox")<br />
The example determines the model of the MyListBox control element, which is located in the first form of the<br />
text document currently open.<br />
If you are not sure of the form of a control element, you can use the option for searching through all forms for<br />
the control element required:<br />
Dim Doc As Object<br />
Dim Forms As Object<br />
Dim Form As Object<br />
Dim Ctl As Object<br />
Dim I as Integer<br />
Doc = ThisComponent<br />
Forms = Doc.Drawpage.Forms<br />
For I = 0 To Forms.Count - 1<br />
Form = Forms.GetbyIndex(I)<br />
If Form.HasByName("MyListBox") Then<br />
Ctl = Form.GetbyName("MyListBox")<br />
Exit Function<br />
End If<br />
Next I<br />
The example uses the HasByName method to check all forms of a text document to determine whether they<br />
contain a control element model called MyListBox. If a corresponding model is found, then a reference to this is<br />
saved in the Ctl variable and the search is terminated.<br />
168 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010