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 PocketBuilder 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 drop-down list, because the list shows built-in data types only.
To specify that a function does not return a value:
Select (None) from the Return Type list
This tells PocketBuilder that the function does not return a value. This is similar to defining a procedure or a void function in some programming languages.
The following table shows the return type you would specify for some different types of function.
If you are defining |
Specify this return type |
---|---|
A mathematical function that does some processing and returns a real number |
real |
A function that takes a string as an argument and returns the string in reverse order |
string |
A function that is passed an instance of window w_calculator, does some processing (such as changing the window's color), then returns the modified window |
w_calculator |