Monday, August 16, 2010

Powerbuilder Structure

One of Powerbuilder's feature is Structure. Structure is a object which made possible for the programmer to store and passing the parameters in different types.

The example below is to explain how to use Structure in Powerbuilder

Let say, you need to passing 4 parameters which have 3 different data types: string, datetime and decimal, when you open a new window.

First, you need to create a new Structure. At the main painter, click Structure button.

Click New to create a new structure

Fill the variables that you want to pass. You can set the different type for each variables.

Save by clicking Save button (of Choose menu File than Save). Type str_dailydiscountreport as a name. str_ is a prefix to represent that the object is a Structure.

In the script that will open the new window, type following code. This code is to declare the new structure variable which pointed to str_dailydiscountreport structure that we have build in the first.

// declare new structure variable
str_dailydiscountreport strReport

// fill each variable in the structure
strReport.sProductCode = sle_productcode.text
strReport.dtDateFrom = datetime(em_datefrom.text)
strReport.dtDateUntil = datetime(em_datefrom.text)
strReport.dDiscount = Dec(em_discount.text)

// Open the new window with passing the structure

How to received?
In event Open of the w_report window, do same with the script above.

// declare new structure variable
str_dailydiscountreport strReport

// receive the structure that passed from the window caller by using message object with PowerobjectParm as property
strReport = message.PowerobjectParm

// extract all the variables inside the structure
MessageBox("Product Code",strReport.sProductCode)
MessageBox("Date From",Str(strReport.dtDateFrom,'dd/mm/yyyy')
MessageBox("Date Until",Str(strReport.stDateUntil,'dd/mm/yyyy')
MessageBox("Discount",Str(strReport.dDiscount,'##.##') + "%"


  1. really its nice post about PowerBuilder. Thanks for sharing this Information.

  2. This comment has been removed by the author.

  3. This structure presentation about PowerBuilder Development its so good. thanks for sharing .

  4. Very Helpfull