1. Daniel Vivier
  2. PowerBuilder
  3. Tuesday, 4 August 2020 20:04 PM UTC

We have some code in our report-viewing window to determine whether VCR-like paging controls (for First, Previous, Next or Last Page) are enabled based on whether there are multiple pages.

However, one of our reports has grouping, with Group 1 having the ResetPageCount property set (resets the page number at each group break).

So what that means is that in some cases, the report might just contain two pages, each of which is "Page 1 of 1". 

In that situation, I don't know how to tell whether there are multiple pages in code. I thought maybe if ResetPageCount could be turned off in the code (if it's currently on), then get the PageCount, then turn it on again, I could solve the problem, but ResetPageCount seems to be a source code only property.

The code I'm currently using to determine whether to enable the VCR buttons is like:

Long ll_rowcount, ll_PageCount, ll_LastRowOnPage
Boolean lbEnabled = TRUE

ll_rowcount = dw_report.RowCount()
ll_PageCount = Long ( dw_report.Describe("Evaluate('PageCount()'," + String( ll_rowcount ) + ")"))
ll_LastRowOnPage = Long(dw_report.Object.DataWindow.LastRowOnPage)
if ll_rowcount = 1 or (ll_PageCount = 1 and ll_rowcount = ll_LastRowOnPage) then
    lbEnabled = FALSE
end if

If we are sitting on the 2nd page (which still gives an evaluation of PageCount() as 1) this sets lbEnabled to FALSE. (And yes, there's a reason, which isn't relevant to explain, why we might be on the 2nd page when running this.)

Ideas? Thanks.

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 5 August 2020 05:28 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Dan,

what you are looking for is the PageAbs() function. It returns the absolute number of the current page. To get the absolute page count you have to call it for last row:

ll_PageCount = Long ( dw_report.Describe("Evaluate('PageAbs()'," + String( ll_rowcount ) + ")"))

HTH,

René

Comment
  1. Daniel Vivier
  2. Wednesday, 5 August 2020 13:31 PM UTC
YES! This is exactly what I needed. Was not aware of that function.

Wouldn't it be nice if the Help on the PageCount() function and the ResetPageCount setting had references to this function?
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 5 August 2020 02:30 AM UTC
  2. PowerBuilder
  3. # 1
  • I seem to remember the pagecount() is updated correctly by going (temporarily) into 'Preview' mode.
  • Since every page has a footer, you could add an (invisible) computed column to the footer with this contents:

count(1 for all)

That would reflect the total number of pages of your report.

 

Not sure if that's any good or might give you an idea.

regards.

Comment
  1. Miguel Leeuwe
  2. Wednesday, 5 August 2020 14:04 PM UTC
Well no need to imagine, :). Have you tried putting it in the footer of your report?

Since it's in the footer of every page, it seems to be counting pages.



You could also do Count('abc' for all) or count( page() for all)

To be honest, I like Mr. Ullrich's solution better. Makes more sense.
  1. Helpful
  1. Brad Mettee
  2. Wednesday, 5 August 2020 14:06 PM UTC
Just to clarify this concept:

count(1 for all) will do an additive count for all groups, and being that it's in the footer of a page, will give an accurate page count.. This counting concept is useful if you have a need for total counts and don't need to add up a column's contents, but do need the number of occurrences.
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 5 August 2020 14:12 PM UTC
Thank you Brad, I wasn't to sure why it worked myself.

BTW: I do have checked the "new page on group break" in my test report, but not sure if that's what makes it work. If a single group doesn't fit on a single page, might it count incorrectly? Not sure.

Anyways the accepted answer is the best.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.