22.01.2015 Views

OpenOffice.org Macros Explained - LibreOffice-NA.US

OpenOffice.org Macros Explained - LibreOffice-NA.US

OpenOffice.org Macros Explained - LibreOffice-NA.US

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Decimal Binary Octal Hexadecimal<br />

13 1101 15 D<br />

14 1110 16 E<br />

15 1111 17 F<br />

16 10000 20 10<br />

17 10001 21 11<br />

18 10010 22 12<br />

Integers are assumed to be expressed as decimal numbers. Commas are not allowed. Hexadecimal numbers<br />

are preceded by “&H” and octal numbers are preceded by “&O” (letter O, not a zero). Unfortunately, there is<br />

no easy method to enter binary numbers. Table 8 presents a few simple guidelines for entering numbers.<br />

Table 8. A few guidelines for entering numbers in OOo Basic.<br />

Example<br />

Use 1000 not 1,000<br />

Description<br />

Write numbers without a thousands separator; do not use commas.<br />

+ 1000 A space is permitted between a leading plus or minus sign and the number.<br />

&HFE is the same as 254<br />

&O11 is the same as 9<br />

Use 3.1415 not 3,1415<br />

Precede a hexadecimal number with &H.<br />

Precede an octal number with &O.<br />

Do not use commas for the decimal.<br />

6.022E23 In scientific notation, the “e” can be uppercase or lowercase.<br />

Use 6.6e-34 not 6.6e -34 Spaces are not allowed in a number. With the space, this evaluates as 6.6 - 34 = -27.4.<br />

6.022e+23<br />

1.1e2.2 evaluates as 1.1e2<br />

The exponent may contain a leading plus or minus sign.<br />

The exponent must be an integer. The fractional portion is ignored.<br />

In general, assigning a String to a numeric variable sets the variable to zero and does not generate an error. If<br />

the first characters in the string represent a number, however, then the string is converted to a number and<br />

the non-numeric portion of the string is ignored — numeric overflow is possible.<br />

Integer variables<br />

An integer is a whole number that may be positive, negative, or equal to zero. Integer variables are a good<br />

choice for numbers representing non-fractional quantities, such as age or number of children. In OOo Basic,<br />

Integer variables are 16-bit numbers supporting a range from -32768 through 32767. Floating-point numbers<br />

assigned to an integer are rounded to the nearest Integer value. Appending a variable name with “%” when it<br />

is declared is a shortcut to declaring it as type Integer.<br />

Listing 9. Demonstrate integer variables.<br />

Sub ExampleIntegerType<br />

Dim i1 As Integer, i2% REM i1 and i2 are both Integer variables<br />

Dim f2 As Double<br />

Dim s$<br />

f2= 3.5<br />

i1= f2 REM i1 is rounded to 4<br />

s = "3.50 => " & i1<br />

36

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

Saved successfully!

Ooh no, something went wrong!