Pages

Monday, November 1, 2010

Powerbuilder Window Function

On my last post about Powerbuilder function, I have mention that there are 2 types of function in Powerbuilder. Now, I will try to explain another function called Window Function.

The main different between Window Function and function, is Window Function must be declared in Window Object, and it should be related with windows object inside.

The way to declare the Window function is almost the same when you declare the function. But for the first step, you need to open your window first, where you want to put the window function inside. Click Declare at drop down menu, then select Windows Functions sub menu.



Specify the name of the function, the arguments, the return value and specify where the function can be used: Public (in any script in the application), Private (only in scripts for events in the object in which the function is defined), or Protected (only in scripts for the object in which the function is defined and its descendants).


Type the script, then save and name wf_datechecked. The script will compare the 2 variables (one is the argument, one is the today's date)

// sample window function, named wf_datechecked
// argument or parameter is dtDateTransaction
// will return TRUE if comparation between dtDateTransaction is smaller than dtToday
// will return FALSE if comparation between dtDateTransaction is bigger or equal than dtToday


DateTime dtToday

dtToday = DateTime(Today(),Now())

If dtDateTransaction >= dtToday THEN
   RETURN FALSE
ELSE
   RETURN TRUE
END IF


To call the function, type script below (on Clicked event of b_checked, for example)
Assumed that you have datawindow called dw_1, and has column inside name dateofbirth.

Boolean bValidDate

bValidDate = wf_datechecked(dw_1.GetItemDateTime(row,"dateofbirth"))

IF bValidDate THEN
   Messagebox("Information","The Date is valid")
ELSE
   Messagebox("Information!","The Date is invalid. You must input the date smaller than today")
END IF

No comments:

Post a Comment