OpenOffice.org OpenOffice - 3.0 Quick Start Guide Page 372

  • Download
  • Add to my manuals
  • Print
  • Page
    / 433
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 371
Another kind of subroutine is called a function. A function is a
subroutine that returns a value. The keyword FUNCTION is used
rather than SUB to define a function. Generated macros are
always of type SUB.
Defining variables using DIM
You can write information on a piece of paper so that you can look at it
later. A variable, like a piece of paper, contains information that can be
changed and read. The DIM statement is similar to setting aside a
piece of paper to be used to store a message or note.
The EnterMyName macro defines the variables
document
and
dispatcher
as type
object
. Other common variable types include
string
,
integer
, and
date
. A third variable, named
args1,
is an array of
property values. A variable of type
array
allows a single variable to
contain multiple values, similar to storing multiple pages in a single
book. Values in an array are usually numbered starting from zero. The
number in the parentheses indicates the highest usable number to
access a storage location. In this example, there is only one value, and
it is numbered zero.
Pulling the macro together
The following details are very complete; it is not important to
understand all of the details. The first line defines the start of the
macro.
sub EnterMyName
Declare two variables:
dim document as object
dim dispatcher as object
ThisComponent refers to the current document.
The CurrentController property of a document refers to a service that
“controls” the document. For example, when you type, it is the current
controller that notices. The current controller then dispatches the
changes to the document’s frame.
The Frame property of a controller returns a main frame for a
document. Therefore, the variable named
document
refers to a
document’s frame, which receives dispatched commands.
document = ThisComponent.CurrentController.Frame
Most tasks in OpenOffice.org are accomplished by dispatching a
command. OOo version 2.0 introduced the dispatch helper service,
which does most of the work to use dispatches in macros. The method
372 Getting Started with OpenOffice.org 3
Page view 371
1 2 ... 367 368 369 370 371 372 373 374 375 376 377 ... 432 433

Comments to this Manuals

No comments