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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Events 216<br />

The figure above shows the<br />

<strong>OpenOffice</strong>.<strong>org</strong> Basic development<br />

environment with a dialog window<br />

that contains two list boxes. You can<br />

move the data from one list to the<br />

other using the buttons between the<br />

two list boxes.<br />

If you want to display the layout on<br />

screen, then you should create the<br />

associated <strong>OpenOffice</strong>.<strong>org</strong> Basic<br />

procedures so that they can be called<br />

up by the event handlers. Even<br />

though you can use these procedures<br />

in any module, it is best to limit their<br />

use to two modules. To make your<br />

code easier to read, you should<br />

assign meaningful names to these<br />

procedures. Jumping directly to a<br />

general program procedure from a<br />

macro can result in unclear code.<br />

The <strong>OpenOffice</strong>.<strong>org</strong> Basic development environment<br />

Instead, to simplify code maintenance and troubleshooting, you should create another<br />

procedure to serve as an entry point for event handling - even if it only executes a single<br />

call to the target procedure.<br />

The code in the following example moves an entry from the left to the right list box of a<br />

dialog.<br />

Sub cmdSelect_Initiated<br />

Dim objList As Object<br />

lstEntries = Dlg.getControl("lstEntries")<br />

lstSelection = Dlg.getControl("lstSelection")<br />

If lstEntries.SelectedItem > 0 Then<br />

lstSelection.AddItem(lstEntries.SelectedItem, 0)<br />

lstEntries.removeItems(lstEntries.SelectItemPos, 1)<br />

Else<br />

Beep<br />

End If<br />

End Sub<br />

If this procedure was created in <strong>OpenOffice</strong>.<strong>org</strong> Basic, you can assign it to an event<br />

required using the property window of the dialog editor.

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

Saved successfully!

Ooh no, something went wrong!