hmmm...I don't how it will work with very long lines, but here's the scoop on shared variables. You use them in formulae. Assignments are := while equality tests are = (kinda like C). All you need to do to start using one is to declare in a formula like:
Shared Numbervar GrossAmount; (you can initialize as well, but I only do that in a formula to reset the amounts.) They are case sensitive.
Back to your case:
In the page header the formula would look something like:
Shared numbervar Lines := 0;
"" //I put this in the formula so nothing will display
In the detail section:
Shared numbervar Lines := Lines + 1;
""
In the group header section under new page before
shared numbervar Lines;
Lines > 20 //the number is not specific, you would want to experiment to see what gives you the best results
Hope this helps