Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Split the line @ specific character length Post Reply Post New Topic
Author Message
cheenu_vasan
Newbie
Newbie
Avatar

Joined: 06 Apr 2011
Location: India
Online Status: Offline
Posts: 16
Quote cheenu_vasan Replybullet Topic: Split the line @ specific character length
     Posted: 14 Sep 2012 at 8:48am
Hey Guys
 
I have one requirement in the crystal report 10.0.0.533 that i have the field label that display nearly multiple lines of data.
 
The requirement was that it should print the line at approx. 60 character length before it gets wrapped to new line below. I see that field label should have the property Can grow set. But is there a way to configure in the runtime to wrap the line based on the character count.
 
Further it shouldnt simply wrap to new line when count is 60. If that leads to the split of the word then we need to move that word to next line so ideally we need to look for the last space before 60 character counr for line to wrap up.
 
Regards
Srinivasan B
Thanks & Regards
Srinivasan B
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 14 Sep 2012 at 9:13am
The only reasonable way of doing this is to use Can Grow, which will automatically set up the word-wrap for you.  Part of the issue is that if you're using a proportional font (MOST fonts ARE proportional - Courier New is one exception) each letter has it's own width.  So, for example, 60 characters with lots of l's and i's will be much narrower than 60 characters with lots of m's and w's.  If you're using a non-proportional font, you might be able to do something similar to this:
Stringvar c;
Numbervar at := 60;
Stringvar result := '';
if length({string field}) < 60 then
  result := {string field};
else
  c := mid({string field}, at, 1);
  While c <> ' ' and at > 0 do
  (
    at := at - 1;
    c := mid({string field}, at, 1);
  );
  if at = 0 then
    result := {string field};
  else
    result = left({string field}, at) + chr(13) + chr(10) +
          mid({string field}, at + 1, length({string field});
);
result
 
Note:  I haven't tested this code, so it will probably need to be tweaked.  Also, this assumes that there are ONLY 2 lines possible.  If there's more than that, you REALLY need to turn on Can Grow and let the auto-word wrap do its thing.
 
-Dell


Edited by hilfy - 14 Sep 2012 at 9:14am
IP IP Logged
cheenu_vasan
Newbie
Newbie
Avatar

Joined: 06 Apr 2011
Location: India
Online Status: Offline
Posts: 16
Quote cheenu_vasan Replybullet Posted: 20 Sep 2012 at 1:40am
thank you, i hope this will work good for upto 2 lines.
Thanks & Regards
Srinivasan B
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum