Subject Re: Report group headers
From Mervyn Bick <invalid@invalid.invalid>
Date Mon, 1 Jan 2024 13:41:25 +0200
Newsgroups dbase.getting-started

On 2023/12/31 20:54, Charlie wrote:
> Happy new year to everyone.
>
> Ken you weren't fooling when you said this is complicated.
>
> I studied the book code but used Mervyn's code as I don't have the example from the book and Mervyn's was easy to copy and paste.  I didn't understand the module that oChild is supposed to equal either but probably because I haven't read the whole book.  I tend to learn from doing not reading.   I think I understand what is going on.  But I am getting an error for a missing rowset which I don't understand.  I get this error after five pages show printed.  But only 2 pages actually print, and the second page doesn't print the header (category) again at the top of the page.
>
> Any help would be appreciated.

The Report designer can handle multiple tables but there have been
reports, especially where more than two tables are involved, of
problems.  I can recall users having to write DIY code to implement a
second masterRowset/masterFields relationship.  I can't recall the
version of dBASE involved and it may well have been resolved for newer
versions of dBASE.  At the time though I opted to completely bypass the
problem by JOINing multiple tables.  This gives me just one rowset to
play with albeit one with what can be quite a bit of redundant data.  I
still use this approach and I've never had any problems including a
report that uses data from 5 tables.

Using Ken's examples from chapter 14 of the dBASE Report book you should
be able to do a copy and paste from PageBreak3.rep without too much
trouble.  Be aware though that diving in at the deep end has it's
drawbacks.  The book is very carefully structured to introduce concepts
step by step.  It can lead to much head scratching if one has missed
earlier steps.

As Ken uses masterRowset/masterFields to set the relationship between
the tables the calculation of the number of records for the next group
is actually simpler than in my example.  He uses the child rowset's
count() method.  I have to physically step through the single rowset to
actually count the records.  The code isn't rocket science but it's 6
lines instead of 1. :-)  It's the price to be paid for JOINing the
tables instead of setting a masterRowset/masterFields relationship.

If a group is running over to a second page without displaying the group
heading on the second page it means you haven't set the group's
headingEveryFrame property true.  In chapter 11 of the dBASE Reports
book Ken explains how to add "continued" to text in the group header
where the number of records forces the group to cross page boundaries.

In the example I posted for you all I wanted was to group the names
alphabetically.  This meant I needed to count records that started with
the same letter.  This is going to cause problems if you have more than
one category starting with the same letter.

Try the following.  It is, however, untested as I can't run your report.

As I said in an earlier post, it essential for the rowset to be ordered
primarily by category.  You can add as many fields to the ORDER BY
clause as you need but the first one MUST be category.

    if not oStream.rowset.endofset
      oStream.rowset.next()
      nCount = 0
      cCategory = oStream.rowset.fields["category"].value
      do while  oStream.rowset.fields["category"].value = cCategory  ;
         and not oStream.rowset.endofset
         oStream.rowset.next()
         nCount ++
      enddo
      oStream.rowset.goto(oStream.bookmark)
   endif

Mervyn.