Calling functions – PB Docs 125

Calling functions

You can call server functions for an OLE control through its
Object property using the following syntax:

If the OLE object is complex, there could be nested properties
or objects within the object that serve as qualifiers for the function
name.

note.png Required parentheses

PowerScript considers all commands to the server either property
settings or functions. For statements and functions to be distinguished
from property settings, they must be followed by parentheses surrounding
the parameters. If there are no parameters, specify empty parentheses.

Arguments and return values and their datatypes

PowerBuilder converts OLE data to and from compatible PowerBuilder datatypes.
The datatypes of values you specify for arguments must be compatible
with the datatypes expected by the server, but they do not need
to be an exact match.

When the function returns a value, you can assign the value
to a PowerBuilder variable of a compatible datatype.

Passing arguments by reference

If an OLE server expects an argument to be passed by reference
so that it can pass a value back to your script, include the keyword REF just
before the argument. This is similar to the use of REF in
an external function declaration:

In these generic examples, the server can change the values
of ls_string and li_return because
they are passed by reference:

This example illustrates the same function call using an OLEObject
variable.

note.png Setting the timeout period

Calls from a PowerBuilder client to a server time out after
five minutes. You can use the SetAutomationTimeout PowerScript
function to change the default timeout period if you expect a specific
OLE request to take longer.

Word and automation

Microsoft Word 6.0 and 7.0 support automation with a command
set similar to the WordBasic macro language. The command set includes
both statements and functions and uses named parameters. Later versions
of Microsoft Word use Visual Basic for Applications (VBA), which
consists of a hierarchy of objects that expose a specific set of
methods and properties.

WordBasic statements

WordBasic has both statements and functions. Some of them
have the same name. WordBasic syntax differentiates between statements
and functions calls, but PowerBuilder does not.

To specify that you want to call a statement, you can include AsStatement! (a value
of the OLEFunctionCallType enumerated datatype)
as an argument. Using AsStatement! is the only
way to call WordBasic statements that have the same name as a function.
Even when the statement name does not conflict with a function name,
specifying AsStatement! is more efficient:

For example, the following code calls the AppMinimize statement:

Named parameters

PowerBuilder does not support named parameters that both WordBasic
and Visual Basic use. In the parentheses, specify the parameter values
without the parameter names.

For example, the following statements insert text at a bookmark
in a Word 6.0 or 7.0 document:

The last two commands in a WordBasic macro would look like
this, where Destination is the named parameter:

In a PowerBuilder script, you would use this syntax to insert
text in a Word 97 or later document:

In the corresponding Visual Basic statement, the named parameter
Text contains the string to be inserted:

note.png Automation is not macro programming

You cannot send commands to the server application that declare
variables or control the flow of execution (for example, IF
THEN
). Automation executes one command at a time independently
of any other commands. Use PowerScript’s conditional and
looping statements to control program flow.

Example of Word automation

To illustrate how to combine PowerScript with server commands,
the following script counts the number of bookmarks in a Microsoft
Word OLE object and displays their names:

note.png Word automation tip

You can check that you are using the correct syntax for Word
automation with the Word macro editor. Turn on macro recording in
Word, perform the steps you want to automate manually, then turn
off macro recording. You can then type Alt+F11 to open
the macro editor and see the syntax that was built. Remember that
PowerBuilder uses square brackets for array indexes.

Example of Word 6.0 and 7.0 automation

The following script counts the number of bookmarks in a Microsoft
Word 6.0 or 7.0 OLE object and displays their names:


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x