Reputation: 67
I am populating a DataWindow with some data. Some of the column names are "Request No", "Status", etc.
"Status" column can contain values like "Pending", "Active","Expired".
Whenever the DataWindow is populated I want to count the number of records in PowerBuilder which are having status as "Active".
After getting the count of the records I will be populating the count in some static text.
Can anybody help me , how to achieve this, as I am new to PowerBuilder.
Thanks
Upvotes: 1
Views: 4103
Reputation: 6225
This will get you your answer, but it introduces you to what we PowerBuilder developers know as "Tilde Hell".
ll_Count = Long (dw.Describe ("Evaluate('sum (if((status = ~~~"Active~~~"),1,0))',1)"))
The tilde-craziness has to do with what each level of string evaluation boils the expression down to for the next evaluation. (~~ boils down to ~, and ~" boils down to " which is useful if your string is enclosed in double quotes)
Evaluate(<expression>, <row>)
inside a Describe()
will return the value for <expression>
on a given row. (Since <row>
is irrelevant to a sum()
operation which works across the full data set, all you need to do is make sure it's a valid row, i.e. in this example, that there is at least one row.)
Good luck,
Terry.
Upvotes: 4
Reputation: 11465
One solution is to filter the DW data by using your criteria, then to get the rows count.
Something like:
dw_ctrl.SetFilter("status='Active'")
dw_ctrl.Filter()
ll_count = dw_ctrl.RowCount()
//...
//don't forget to reset filter after that
dw_ctrl.SetFilter("")
dw_ctrl.Filter()
Upvotes: 3