A frequent request is how to add page of page number to Clarion reports.
The issue is when any given page of a report is generated the report engine does not know how many page the total report will contain.
This is code from the TinTools report previewer. This was a free ware tool available in the late 90s/early 2000s.
Since it was a free-ware tool that is no longer downloadable I think it is OK to publish it on ClarionHub.
The key is to add a control to your report with the literal text page xxxxx of xxxxx. This code searches the generated meta files after the report completes looking for that text and replacing it with the correct values for that page.
This code needs to be called after the report has completed. The ReportManager EndReport method after the parent call is a good place.
This method is modified from the original to work as a method of the ReportManager class instead of the TinTools previewer.
ReportManager.CheckForPageNum PROCEDURE
PAGENUMOFWRK STRING(19)
PREV:MetaFileName STRING(100),Static
PREV:Metafile FILE,DRIVER('dos'),NAME(PREV:MetaFileName)
Record RECORD,PRE()
MetaLine STRING(256)
END
END
ImageCount Short
CODE
ImageCount = RECORDS(SELF.PreviewQueue)
LOOP TKCounter1# = 1 to ImageCount
GET(SELF.PreviewQueue, TKCounter1#)
PREV:MetaFileName = SELF.PreviewQueue
OPEN(PREV:MetaFile)
IF ERRORCODE(); CYCLE.
TKMetaPointer# = 0
LOOP
SET(PREV:MetaFile, TKMetaPointer#)
NEXT(PREV:MetaFile)
TKCounter2# = instring('Page xxxxx of xxxxx', MetaLine, 1, 1)
IF TKCounter2# > 0
PAGENUMOFWRK = 'Page ' & FORMAT(TKCounter1#,@s5)
PAGENUMOFWRK = CLIP(PAGENUMOFWRK) & ' of ' & FORMAT(ImageCount,@s5)
PAGENUMOFWRK = CENTER(CLIP(PAGENUMOFWRK),19)
MetaLine = SUB(MetaLine,1,TKCounter2#-1)|
& PAGENUMOFWRK |
& SUB(MetaLine,TKCounter2#+19,LEN(MetaLine))
PUT(PREV:MetaFile)
BREAK
END
IF ERRORCODE() OR EOF(PREV:MetaFile); BREAK.
TKMetaPointer# = POINTER(PREV:MetaFile) + 236
END
CLOSE(PREV:MetaFile)
END
I can’t take any credit for this (I’d most likely write it a bit differently ), but it does work.
Enjoy,
Rick