Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line objects in report 4

Status
Not open for further replies.

torturedmind

Programmer
Jan 31, 2002
1,052
PH
Good day to all.

So we have this report that we submit to our government for update purposes. For illustration only, let's say...
Code:
+-------------------------------------------------------------+
| fld1  |   fld2   |          fld3          |       fld4      |
+-------+----------+------------------------+-----------------+
| val1  |   val2   |          val3          |       val4      | [i]record 1[/i]
+-------+----------+------------------------+-----------------+
| val1  |   val2   |          val3          |       val4      | [i]record 2[/i]
+-------+----------+------------------------+-----------------+
| val1  |   val2   |          val3          |       val4      | [i]record 3[/i]
+-------+----------+------------------------+-----------------+
| val1  |   val2   |          val3          |       val4      | [i]record 4[/i]
+-------+----------+------------------------+-----------------+
|   :   |     :    |            :           |        :        |
+-------+----------+------------------------+-----------------+
| val1  |   val2   |          val3          |       val4      | [i]record n[/i]
+-------+----------+------------------------+-----------------+
               [i]***** NOTHING FOLLOWS *****[/i]

We all know that the horizontal lines separate each record and when EOF() is encountered, these lines also stop printing. Now our government wants these lines to fill the rest of the page even if there are no more records to print. I cannot do records-per-page method because several fields are "Stretch with overflow" so there will be varying number of records per page. I personally think that the change they wanted defeats the purpose of the "***** NOTHING FOLLOWS *****" idea. My question is - how can I do that? Is it even possible?

TIA

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
Good morning, Kilroy.

I agree. It's a bit daft, and defeats the object of the existing footer. But you can't fight a government request.

One possibility off the top of my head:

Before you run the report, calculate how many horizontal lines you will need (based on the record count). Then create a variable that contains that number of lines. Place an expression in the report summary band, and set it to that variable.

I don't know if that would work, but it might be worth trying. And there might be a simpler method. I don't know.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Another thought:

Calculate the number of lines you will need, as above. Then add that many (blank) records to the cursor that drives the report. Within the detail band, set each field's Print When so that it will not print for the records that you have just added (you can base that test on the record count, or add a flag to the record). Next, add a single line to the bottom of the detail band, and set that line's Print When to tell it to print for the records you added (again, using the record count or the flag).

Again, this is just off the top of my head. I'd be interested to know if anyone else comes up with a more direct method.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
Torturemind uses "Stretch with overflow" with makes it much more difficult the calculate the number of lines though? Especially with proportional fonts.
Maybe, if courier font is accpeted, it's some more easy by counting the number of chars.
THis wahat came up right now.
-Bart
 
Bart,

I take your point about "Stretch with overflow" making it difficult to calculate lines based on the record count. But it might be possible to do so using _PLINENO. When you print the last line (which you detect by comparing RECCOUNT() to RECNO()), you check _PLINENO and use that to calculate how many lines remain on the page. You then use that information to determine how many horizontal lines to place in the variable.

I'm assuming it's possible to change the value of a variable while the report is running, and to have that new value recognised in the report. I don't know if that's possible. Needs some experimenting.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I would do he simplest thing...

Work out the max number of blank lines on a page, add that many blank records to the end of the cursor
and throw away the extra page / don't print it where necessary...


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Good morning. Thank you all for the inputs. Internet is a bit jittery right now. Tropical cyclone Melor has just passed us and it's still raining very hard. Good thing we still have electricity.

Anyway, I also did what Sir Mike suggested but produced the same results - fail. Currently, I'm reading Sir Vilhelm's suggestion. Maybe I'll try them out later. I agree that Sir Griff's is the simplest. If all else fail, it will be the best and only option. And if that's the case, I just hope the end-users will not print the blank pages (i.e., not containing "real" records) as we are practicing resource conservation. Don't want the company to blame me for the wasted papers. [wink]

Thanks again.[orientalbow]

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
It might be possible to not actually print the last page (the one after the one with the last real record on it).

If you keep a track of the page number for each of the 'real records' as the report is processed, and then change the
'print when' for the details so that it only actually prints if the detail is 'real' or is 'not real, but on the same page
as the last real detail'.

This may be wishful thinking on my part, I seem to remember using a trick like that to get a 'page x of y' on
a report many years ago... before that was available in VFP anyway (VFP6ish)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Griff, you're probably thinking of _PAGENO. This tells you the number of the current page being printed. And unlike _PLINENO, it does work during report execution (I just tried it).

So, it would be possible to add an expression to the report that fires (thought Print When) on the last record; the expression would call a function, passing _PAGENO as a parameter; the function would record that value in a variable.

The trouble is that, by the time you do that, you will already have launched the report, and it will be too late to vary the page numbers that are actually to be printed. But you could get round that by doing two passes of the report. The first pass would print to a file, that would then be discarded. That first pass would record the relevant page number. You then call REPORT FORM a second time, specifying the actual pages to be printed.

Kilroy, does that make sense? It know it sounds complicated, especially when compared to my other suggestion of getting the users to preview the report before printing. But it has the advantage of being transparent to the users.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike

That sounds like an idea

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
This is a solution for the case when the height of the detail band is fix, without adding supplementary rows to the cursor.
A solution for the case of variable height of the detail band, requires SET REPORTBEHAVIOR 90 and is more complicated
The attachment contains a small prg and a small report

1 Define 3 report variables :
a) nRowPerPage
- Value to store=nRowPerPage
- Initial value=number of regular detail rows (depends of several things like the hight of the detail band and the paper size)
(Be careful that the height of the detail band changes when you edit the band. Check and adjust every time this value)
- Reset value based on=Report
- Calculation type=None
b) nRowOutput (number of rows already printed on the last page of the report)
- Value to store=0
- Initial value=0
- Reset value based on=Page
- Calculation type=Count
c) nRowSupl
- Value to store=nRowPerPage
- Initial value=number of the supplementary detail rows (updated while the report is printed)
- Reset value based on=Report
- Calculation type=None

2 The objects from the detail band, except the desired line must have :
- Print when=iif(recc(MyCursor)=1,recno()=1,nRowSupl=0)
where MyCursor is the cursor name

3 The detail band's On exit event, must contain:
iif(recno()=reccount() and nRowOutput<nRowPerPage,_vfp.docmd("lastrow (nRowPerPage,nRowOutput,@nRowSupl)"),1)

where lastrow can be this procedure :

PROCEDURE lastrow
LPARAMETERS nRowSupl
SKIP -1
nRowSupl=nRowSupl+1
RETURN

4 To manage the case when the cursor has only a single row, in the report's DataEnvironment Init method I placed this code :

LOCAL ccur,lcfield
ccur=SYS(2015)
lcfield=SYS(2015)
IF RECCOUNT()=1 && a dummy cursor with two rows
CREATE CURSOR (ccur) (&lcfield I AUTOINC)
APPEND BLANK
APPEND BLANK
SELECT (ccur)
ENDIF


Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
 http://files.engineering.com/getfile.aspx?folder=db1c8ec1-34d7-48e8-a610-464ef350bdbd&file=praisach_repo_rows.zip
Thank you good sirs for all your inputs. Really helped a lot as to where to go from here.

And here's what I did:
1. Determined how many lines are printed every page. It's normally 24 without the "Stretch with overflow".
2. Since the resulting cursor was created as READWRITE, in the "Preview/Print" button, I included the ffg. code:
Code:
LOCAL i
i = 0
FOR i = 1 TO 24    && the max. no. of lines printed per page
[indent]APPEND BANK[/indent]
ENDFOR
3. Wrote a small function DELBLANK with the following content:
Code:
IF linecounter = 24 AND EMPTY(myreport.anycharfield)
    IF NOT EOF()
        SKIP
    ENDIF

    DELETE ;
	REST ;
	FOR EMPTY(myreport.anycharfield)
ENDIF
4. Created a report variable LINECOUNTER with initial value of 0 and resets at every page.
5. Placed a textbox/fieldbox in the detail band with the LINECOUNTER as its expression. I made the foreground white so it's not visible in the print out.
6. Placed another textbox/fieldbox in the page footer this time and put DELBLANK() (the function name) as its expression. Foreground is also white.

That's it. Works for me. Maybe could work for anyone who might be in the same predicament.

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
Glad you found a solution, Kilroy. And thanks for posting if for other people's benefit.

One question: You said originally that the report contains fields that are "stretch with overflow". If that's the case, does the line counter get correctly updated when a given field extends over multiple lines?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Good morning Sir Mike.

MikeLewis said:
...does the line counter get correctly updated when a given field extends over multiple lines?

Yes. I also never changed anything in the "Strecth with overflow" thing. I made a sample record with one of the fields having a longer value and it stretches to two lines, making the line counter 23 only.
WtRcsGN.png


I know that the next question is - what if the total number records is exactly 23 and that one of those records stretches to occupy two lines? Or maybe multiple records stretching to several lines with the last line as the last record? Well, I'm working on it right now and modifying the DELBLANK function. Just need to make some more tests in various scenarios before giving this to the client.

[hammer] If my brain hurts figuring this out, I will be here again calling for help. [laughtears]

kilroy [knight]
philippines

"Once a king, always a king. But being a knight is more than enough."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top