Defining a return type
Many functions perform some processing and then return a value.
That value can be the result of the processing or a value that
indicates whether the function executed successfully or not. To have
your function return a value, you need to define its return type,
which specifies the datatype of the returned value.
You must code a return statement in the function that specifies
the value to return. See Returning a
value. When you call the function in a script or another
function, you can use an assignment statement to assign the returned
value to a variable in the calling script or function. You can also
use the returned value directly in an expression in place of a
variable of the same type.
To define a function’s return type
-
Select the return type from the Return Type drop-down list
in the Prototype window, or type in the name of an object type you
have defined.You can specify any PowerBuilder datatype, including the
standard datatypes, such as integer and string, as well as objects
and controls, such as DataStore or MultiLineEdit.You can also specify as the return type any object type that
you have defined. For example, if you defined a window named
w_calculator and want the function to process the window and
return it, type w_calculator in the Return Type list. You cannot
select w_calculator from the list, because the list shows only
built-in datatypes.
To specify that a function does not return a value
-
Select (None) from the Return Type list.
This tells PowerBuilder that the function does not return a
value. This is similar to defining a procedure or a void function
in some programming languages.
Examples of functions returning
values
The following examples show the return type you would specify
for some different functions:
|
If you are defining |
Specify this return type |
|---|---|
|
A mathematical function that does some processing |
real |
|
A function that takes a string as an argument and |
string |
|
A function that is passed an instance of window |
w_calculator |