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)

1:  // sample window function, named wf_datechecked  
2:  // argument or parameter is dtDateTransaction  
3:  // will return TRUE if comparation between dtDateTransaction is smaller than dtToday  
4:  // will return FALSE if comparation between dtDateTransaction is bigger or equal than dtToday  
6:  DateTime dtToday  
8:  dtToday = DateTime(Today(),Now())  
10:  If dtDateTransaction >= dtToday THEN  
11:       RETURN FALSE  
12:  ELSE  
13:       RETURN TRUE  
14:  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.

1:  Boolean bValidDate  
3:  bValidDate = wf_datechecked(dw_1.GetItemDateTime(row,"dateofbirth"))  
5:  IF bValidDate THEN  
6:       Messagebox("Information","The Date is valid")  
7:  ELSE  
8:       Messagebox("Information!","The Date is invalid. You must input the date smaller than today")  
9:  END IF  

No comments:

Post a Comment