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.

Procedures and Functions 35<br />

The method for passing parameters to procedures and functions in <strong>OpenOffice</strong>.<strong>org</strong> Basic is virtually<br />

identical to that in VBA. By default, the parameters are passed by reference. To pass parameters as<br />

values, use the ByVal keyword. In VBA, you can also use the keyword ByRef to force a parameter to be<br />

passed by reference. <strong>OpenOffice</strong>.<strong>org</strong> Basic recognizes but ignores this keyword, because this is already<br />

the default procedure in <strong>OpenOffice</strong>.<strong>org</strong> Basic.<br />

Optional Parameters<br />

Functions and procedures can only be called up if all the necessary parameters are passed<br />

during the call.<br />

<strong>OpenOffice</strong>.<strong>org</strong> Basic lets you define parameters as optional, that is, if the corresponding<br />

values are not included in a call, <strong>OpenOffice</strong>.<strong>org</strong> Basic passes an empty parameter. In the<br />

following example the A parameter is obligatory, whereas the B parameter is optional.<br />

Sub Test(A As Integer, Optional B As Integer)<br />

' ...<br />

End Sub<br />

The IsMissing function checks whether a parameter has been passed or is left out.<br />

Sub Test(A As Integer, Optional B As Integer)<br />

Dim B_Local As Integer<br />

' Check whether B parameter is actually present<br />

If Not IsMissing (B) Then<br />

B_Local = B ' B parameter present<br />

Else<br />

B_Local = 0 ' B parameter missing -> default value 0<br />

End If<br />

' ... Start the actual function<br />

End Sub<br />

The example first tests whether the B parameter has been passed and, if necessary, passes<br />

the same parameter to the internal B_Local variable. If the corresponding parameter is not<br />

present, then a default value (in this instance, the value 0) is passed to B_Local rather than<br />

the passed parameter.<br />

The ParamArray keyword present in VBA is not supported in <strong>OpenOffice</strong>.<strong>org</strong> Basic.

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

Saved successfully!

Ooh no, something went wrong!