21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Working With Forms 231<br />

Accessing the Model of Control Element Forms<br />

The models of the control elements of a form are available through the GetByName method<br />

of the Object form:<br />

Dim Doc As Object<br />

Dim Form As Object<br />

Dim Ctl As Object<br />

Doc = StarDesktop.CurrentComponent<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<br />

the first form of the text document currently open.<br />

If you are not sure of the form of a control element, you can use the option for searching<br />

through all forms for 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 = StarDesktop.CurrentComponent<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<br />

determine whether they contain a control element model called MyListBox. If a<br />

corresponding model is found, then a reference to this is saved in the Ctl variable and the<br />

search is terminated.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!