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.

Conversion Functions 45<br />

converts any data types into a Boolean value.<br />

CDate(Var)<br />

converts any data types into a date value.<br />

You can use these conversion functions to define how <strong>OpenOffice</strong>.<strong>org</strong> Basic should perform<br />

these type conversion operations:<br />

Dim A As String<br />

Dim B As Integer<br />

Dim C As Integer<br />

B = 1<br />

C = 1<br />

A = CStr(B + C) ' B and C are added together first, then<br />

' converted to the string "2"<br />

A = CStr(B) + CStr(C) ' B and C are converted into a string,then<br />

' combined to produce the string "11"<br />

During the first addition in the example, <strong>OpenOffice</strong>.<strong>org</strong> Basic first adds the integer<br />

variables and then converts the result into a chain of characters. A is assigned the string 2.<br />

In the second instance, the integer variables are first converted into two strings and then<br />

linked with one another by means of the assignment. A is therefore assigned the string 11.<br />

The numerical CSng and CDbl conversion functions also accept decimal numbers. The<br />

symbol defined in the corresponding country-specific settings must be used as the decimal<br />

point symbol. Conversely, the CStr methods use the currently selected country-specific<br />

settings when formatting numbers, dates and time details.<br />

The Val function is different from the Csng, Cdbl and Cstr methods. It converts a string into<br />

a number; however it always expects a period to be used as the decimal point symbol.<br />

Dim A As String<br />

Dim B As Double<br />

A = "2.22"<br />

B = Val(A) ' Is converted correctly regardless of the<br />

' country-specific settings<br />

Checking the Content of Variables<br />

In some instances, the date cannot be converted:<br />

Dim A As String<br />

Dim B As Date<br />

A = "test"

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

Saved successfully!

Ooh no, something went wrong!