Thursday, October 28, 2010

Powerbuilder Function

In every modern programming languages, there is a feature call FUNCTION, as well as Powerbuilder.

FUNCTION is a collection of scripts or statment which it can be re-used. Normally, FUNCTION has a return value.

In Powerbuilder, there are 2 types of FUNCTION: Function and Window Function. The different is FUNCTION can be use anywhere in object that has capabilities to call function, but Window Function just can called in the window itself.

In this article, I will show you the steps how to declare the function in Powerbuilder. I'm using Powerbuilder version 6.5 and I'm sure it will be the same for all versions above

In the main toolbar, click Function painter.

Click New to create a new Function

Type the name of the function, in the example: f_yearafter
Also specify the type of return variable, in this example: date
Function can has many parameters. Parameters can used to passing some value(s) into function, so later can be used to process or calculate something in the script of function. Beside the name of parameters, you must specify the type of parameters, and the Pass By. There are 3 types of Pass by: value, reference, and readonly. Use reference if you want to change the value parameter then inside the function script.
Click OK to create.

Now you can type the script inside the.
In this example, we create a function call f_yearafter. The function will return a date type value, which it is the date result after some year added.

Once the function created, you can't change or rename the function name, but you can still change the return value, the parameter, etc. Please pay the attention, changing all of that value, will affect into the script inside the function. You can click the function painter icon in the toolbar, to edit the function

To call the function, just add the script like this:

Date dReturnFunction

//add 2 years for the date
dReturnFunction = f_yearafter("01/01/2008",2) // will return "01/01/2010"

No comments:

Post a Comment