Print Page | Close Window

Count number of lines of text

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17923
Printed Date: 18 May 2024 at 11:33pm


Topic: Count number of lines of text
Posted By: OptivaReporter
Subject: Count number of lines of text
Date Posted: 05 Nov 2012 at 6:01am
Hoping someone might have done this:  determine the actual number of lines used in a text field of given width, font, etc. at runtime:
 
Details:
I have a large text field that can have variable contents, i.e. short lines of text:
   the
   quick
   brown
   fox...
 
or more paragraph style text:
   the quick brown fox...
 
I need to determine how many lines are actually generated in the output in order to handle continuation pages.
I can count number of line feeds, I can count characters, but what I need to know is how many actual lines are being used given the design's field width and font type/size rather than guess at how much space the text field needs.
 
The "Can Grow" format feature allows you to select a specific number of lines to allow growth, so I'm hoping there is some way to capture the number of lines the text would result?
 
I don't see any such functions listed in report designer.
Any easy or not-so-easy suggestions appreciated!



Replies:
Posted By: hilfy
Date Posted: 06 Nov 2012 at 5:26am
There is no way to get that information from within the report.  What are you trying to do that you need it for?  In order to span multiple pages from a single text block, right-click on it and go to Format....  Turn on "Can Grow" and turn OFF "Keep Together".
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: OptivaReporter
Date Posted: 06 Nov 2012 at 5:30am
Thanks, I was afraid of that.
 
The report (it's the USDA FSIS report for food manufacturer's if that helps) is a government form, which has a specific page for "process instructions".  If those instructions spill over, the remainder goes not on the very next page, but on a page much later in the document, so simple automatic line breaking isn't sufficient.
 
Thanks though, figured it was worth an ask!


Posted By: hilfy
Date Posted: 06 Nov 2012 at 6:01am
You could potentially count the number of Carriage Returns (chr(13) or chr(10) - I never remember which...) in the field, but that won't get you the total number of lines because of the word wrap for longer lines.  You might be able to do something using the number of Carriage Returns along with the total number of characters.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: OptivaReporter
Date Posted: 06 Nov 2012 at 6:17am
That's actually what I've done - calculated "characters per line return", then picked a cutoff point that varies depending on the CPLR value, then some more creative stuff to find the nearest space or line return within 50 characters after that to actually break (so I'm not breaking within a word)
 
But it's a crazy load of duck tape & chicken wire that I was hoping had a better solution.  Glad to know I'm not completely nuts!
 
Thanks again



Print Page | Close Window