Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
This variable is that rare bird—a system variable that works in the most up-to-date way of getting output, but not very well in the older, obsolete ways. It contains the current page number and can be used to put the page number on a report. Although you can use it with ? and ?? output, _PageNo’s value there is based solely on the number of lines output and _PLength—it doesn’t notice when you issue EJECT (though EJECT PAGE
does properly update _PageNo). With @..SAY output, we can’t get anything sensible from _PageNo.
_PAGENO = nPageNumber
An often-asked question is, “How do I put ‘Page X of Y’ on my report?” The Report Writer doesn’t support this natively, but you can use _PageNo to create a workaround. First, set up a variable or property to store the total pages in the report (remember, it must be in scope while the report runs). Initialize it to 0, then put it into your report’s footer after the page number, in the “Page X of Y” format. When you run the report, you’ll do it twice, first with the NOCONSOLE and TO FILE options. When it finishes the first pass, store the value of _PageNo to the variable or property. Now run it again to its normal destination, and the total number of pages properly displays on the report.
* To implement Page X of Y on a report, you
* might use the following expression:
"Page "+LTRIM(STR(_PAGENO))
* In the report footer, use an expression like the following:
"Page "+LTRIM(STR(_PAGENO))+" of "+LTRIM(STR(nTotalPages))
* Then run the following code:
PRIVATE nTotalPages REPORT FORM MyReport TO FILE Temp.RPT NOCONSOLE
DELETE Temp.RPT
NTotalPages = _PAGENO
REPORT FORM MyReport TO PRINT