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.

Strings 50<br />

The function searches through the transferred Search string in a loop by means of InStr in<br />

the original term Source. If it finds the search term, it takes the part before the expression<br />

and writes it to the Result return buffer. It adds the new Part section at the point of the<br />

search term Search. If no more matches are found for the search term, the function<br />

establishes the part of the string still remaining and adds this to the return buffer. It<br />

returns the string produced in this way as the result of the replacement process.<br />

Since replacing parts of character sequences is one of the most frequently used functions,<br />

the Mid function in <strong>OpenOffice</strong>.<strong>org</strong> Basic has been extended so that this task is performed<br />

automatically. The following example replaces three characters with the string is from the<br />

sixth position of the MyString string.<br />

Dim MyString As String<br />

MyString = "This was my text"<br />

Mid(MyString, 6, 3, "is")<br />

Formatting Strings<br />

The Format function formats numbers as a string. To do this, the function expects a Format<br />

expression to be specified, which is then used as the template for formatting the numbers.<br />

Each place holder within the template ensures that this item is formatted correspondingly<br />

in the output value. The five most important place holders within a template are the zero<br />

(0), pound sign (#), period (.), comma (,) and dollar sign ($) characters.<br />

The 0 character within the template ensures that a number is always placed at the<br />

corresponding point. If a number is not provided, 0 is displayed in its place.<br />

A . stands for the decimal point symbol defined by the operating system in the<br />

country-specific settings.<br />

The example below shows how the 0 and . characters can define the digits after the decimal<br />

point in an expression:<br />

MyFormat = "0.00"<br />

MyString = Format(-1579.8, MyFormat) ' Provides "-1579,80"<br />

MyString = Format(1579.8, MyFormat) ' Provides "1579,80"<br />

MyString = Format(0.4, MyFormat) ' Provides "0,40"<br />

MyString = Format(0.434, MyFormat) ' Provides "0,43"<br />

In the same way, zeros can be added in front of a number to achieve the desired length:<br />

MyFormat = "0000.00"<br />

MyString = Format(-1579.8, MyFormat) ' Provides "-1579,80"<br />

MyString = Format(1579.8, MyFormat) ' Provides "1579,80"<br />

MyString = Format(0.4, MyFormat) ' Provides "0000,40"<br />

MyString = Format(0.434, MyFormat) ' Provides "0000,43"

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

Saved successfully!

Ooh no, something went wrong!