21.08.2013 Views

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - OpenOffice.org wiki

OpenOffice.org BASIC Guide - 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.

Constants<br />

Const A = 10<br />

You can also specify the constant type in the declaration:<br />

Const B As Double = 10<br />

Scope of Constants<br />

Constants have the same scope as variables (see Scope and Life Span of Variables), but the syntax is slightly<br />

different. A Const definition in the module header is available to the code in that module. To make the definition<br />

available to other modules, add the Public keyword.<br />

Public Const one As Integer = 1<br />

Predefined Constants<br />

<strong>OpenOffice</strong>.<strong>org</strong> Basic predefines several constants. Among the most useful are:<br />

True and False, for Boolean assignment statements<br />

PI as a type Double numeric value<br />

Dim bHit as Boolean<br />

bHit = True<br />

Dim dArea as Double, dRadius as Double<br />

' ... (assign a value to dRadius)<br />

dArea = PI * dRadius * dRadius<br />

Operators<br />

<strong>OpenOffice</strong>.<strong>org</strong> Basic understands common mathematical, logical, and comparison operators.<br />

Mathematical Operators<br />

Mathematical operators can be applied to all numbers types, whereas the + operator can also be used to<br />

concatenate strings.<br />

+ Addition of numbers and date values, concatenation of strings<br />

& Concatenation of strings<br />

- Subtraction of numbers and date values<br />

* Multiplication of numbers<br />

/ Division of numbers<br />

\ Division of numbers with a whole number result (rounded)<br />

^ Raising the power of numbers<br />

MOD modulo operation (calculation of the remainder of a division)<br />

Note – Although you can use the + operator to concatenate strings, the Basic interpreter can become confused<br />

when concatenating a number to a string. The & operator is safer when dealing with strings because it assumes<br />

that all arguments should be strings, and converts the arguments to strings if they are not strings.<br />

22 <strong>OpenOffice</strong>.<strong>org</strong> 3.2 <strong>BASIC</strong> <strong>Guide</strong> · March 2010

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

Saved successfully!

Ooh no, something went wrong!