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.

Other Instructions 40<br />

Other Instructions<br />

Type. . . End Type<br />

A struct is a collection of data fields, that can be manipulated as a single item. In older<br />

terms, you may think of a struct as a record, or part of a record.<br />

The → API often uses pre-defined structs, but these are UNO structs, a higly-specialized<br />

kind of struct.<br />

Definition<br />

With the Type...End Type statements, you can define your own (non-UNO) structs:<br />

Type aMenuItem 'assign the name of the type<br />

'Define the data fields within the struct. Each<br />

' definition looks like a Dim statement, without the "Dim".<br />

aCommand as String<br />

aText as String<br />

End Type 'close the definition<br />

Instance<br />

The Type definition is only a pattern or template, not a set of actual variables. To make an<br />

instance of the type, actual variables that can be read and stored, use the Dim As New<br />

statement:<br />

Scope<br />

Dim maItem as New aMenuItem<br />

As shown in the example below, the Type definition may be written at the start of a module<br />

(before the first Sub or Function). The definition will then be available to all routines in the<br />

module.<br />

As of <strong>OpenOffice</strong>.<strong>org</strong> Version 3.0, unlike variables, there is no way to make the definition<br />

accessible outside of the module.<br />

An instance of the new type is a variable, and follows the usual rules for variable scope.<br />

An example of how to use the definition, and how to reference the fields within an instance,<br />

appears in the section on With...End With.

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

Saved successfully!

Ooh no, something went wrong!