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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to split sentence text to wrap properly.

Status
Not open for further replies.

Statey603

Programmer
Nov 10, 2009
196
US
Hi,

Crystal Reports 2011 SP7. I have an report input parameter where the user can enter text. The desired presentation is to show the text as indented bullet items. Since the Crystal Input Parameters do not support multiple line input parameters, I devised a scheme to have the user precede each bullet line with a plus sign character. I have a formula that uses the replace function to replace the plus sign with Carriage Return, Carriage Return, Tab, Bullet, Tab.

Code:
Replace({?bullet_input}, "+", ChrW(13) + ChrW(13) + ChrW(9) + ChrW(9679) + ChrW(9))

This works great, however, if the bullet text wraps to the next line, the next line's text does not indent to where the bulleted text begins.

For example:
Input text:
+ Try a thing you haven’t done three times. Once, to get over the fear of doing it. Twice, to learn how to do it. And a third time, to figure out whether you like it or not. + Courage is not the absence of fear, but rather the judgement that something else is more important than fear.

Desired output:
[ul]
[li]Try a thing you haven’t done three times. Once, to get over the fear of doing it. Twice, to learn how to do it. And a third time, to figure out whether you like it or not.[/li]
[li]Courage is not the absence of fear, but rather the judgement that something else is more important than fear.[/li]
[/ul]

Actual Report Output:

____+_Try a thing you haven’t done three times. Once, to get over the fear of doing it. Twice, to learn how to do it. And a third time, to figure out whether you like it or not.
____+_Courage is not the absence of fear, but rather the judgement that something else is more important than fear.

NOTES:
1. See how the wrapped bulleted text does not align below the text above it, it left justifies.
2. I used underscores to represent spaces and plus signs to represent bullets since the HTML in this forum will not display these characters.

I think I need to Split the text for each bullet on a space character based on the maximum number of characters that can fit on a bulleted line. In my case the bullet line wraps at 95 characters, so I think I need to find the last space in the text at less than 95 and insert a CR and a couple TABS.

I appreciate any suggestions on how to implement this.

P.S. I can't believe that Crystal Reports does not support multiple line text input.

Thanks,

 
Hi Statey,

Have you got the solution please share , similar i am facing.

Regards
Bala
 
Hi Ian,
I asked Statey whether he had solution to share.

Even i remove bullet and then free standing text box will work a fixed lines. But I am trying to build a resume layout where the input text paragraph/sentence with bullets are not of fixed length or fixed lines it depends individual resume per person.

Regards:
Bala
 
I got this working........

Background
For bulleted items, user precedes each bullet with a Plus Sign [+] character. NOTE: Due to Crystal parameter screen limitation of not allowing multiple lines of text in a string parameter, the user must concatenate all lines of input text into a single line and then paste into the parameter textbox. I also added the capability for the user to use a Tilde [~] character to denote a Linefeed. I added WrapLength to determine a point at which to wrap the text to the next line. The involved having to break up the input text into an array of words.

Here is my formula.

//------------------------------------------------------------------------------------------
// Formula: 2nd_sentence_with_determination
//------------------------------------------------------------------------------------------
// Append the text selected for the Determination parameter to the Determination sentence text.
// Text will be a numeric bulleted list. A plus sign [+] will denote a bullet item.
// Used numbered bullets unless only one, then use a circular bullet.
//------------------------------------------------------------------------------------------
Local StringVar sentence_text;
Local StringVar determ_text;
sentence_text := "After completion of the investigation a founded determination was made. The ";
sentence_text := sentence_text + {?reason_reasons} + " for this determination ";
if ({?reason_reasons} = "reasons") then
(
sentence_text := sentence_text + "are: ";
)
else
(
sentence_text := sentence_text + "is: ";
);
//---------------------------------------------------------------------------------------
// Determination Reason(s)
//---------------------------------------------------------------------------------------
// If Plus Sign [+] detected, format bulletted text
// If Tilde [~] detected, replace tilde with CR, CR, TAB
//------------------------------------------------------------
// CARRIAGE RETURN: ChrW(13), TAB: ChrW(9), BULLET: ChrW(9679)
//---------------------------------------------------------------------------------------
NumberVar TotalInputLength;
NumberVar BulletSectionBgn;
NumberVar BulletSectionEnd;
StringVar bullet_section;
StringVar non_bullet_section;
StringVar non_bullet_text;
BooleanVar bNoBulletSection;


TotalInputLength := Length({?determination_reasons});

// Get position of 1st Plus Sign [bullet bgn marker]
BulletSectionBgn := InStr({?determination_reasons}, "+");

// Get position of Equal Sign [bullet end marker]
BulletSectionEnd := InStr({?determination_reasons}, "=");
If BulletSectionEnd = 0 then
BulletSectionEnd := TotalInputLength;

If BulletSectionBgn > 0 then
bullet_section := Mid({?determination_reasons}, BulletSectionBgn, (BulletSectionEnd - BulletSectionBgn)+1);

if BulletSectionBgn > 0 then
(
// format bulletted text
StringVar all_text;
StringVar bullet_text;
NumberVar Idx;
NumberVar x;
NumberVar BulletLen;
NumberVar NewBulletLen;
StringVar new_bullet_text;
StringVar array bullet_array;
StringVar array word_array;
NumberVar BulletCount;
NumberVar WordCount;
NumberVar WrapLen;
NumberVar Pos;
StringVar Rules;
StringVar BulletType;
StringVar LineFeedVal;
NumberVar NumLFsBetweenBullets;
StringVar LineFeeds;
NumberVar WrapLength;

WrapLength := 100;
NumLFsBetweenBullets := 2;

// put the entire input into the all_text variable
all_text := bullet_section;

LineFeeds := "";
For Idx := 1 To NumLFsBetweenBullets Do
(
LineFeeds := LineFeeds + ChrW(13);
);

bullet_array := split(all_text, "+");

BulletCount := count(bullet_array);

// Loop – break up all_text into individual lines (prefaced with plus sign)
For Idx := 1 To BulletCount Do
(
WrapLen := 0;
// If only one bullet, just use a round bullet //12/28/2017
If BulletCount = 2 then
(
new_bullet_text := LineFeeds + ChrW(9679) + ChrW(9);
)
else
(
new_bullet_text := LineFeeds + totext(Idx-1, 0, "") + "." + ChrW(9);
);

BulletLen := Length(bullet_array[Idx]);
If BulletLen > 0 then
(
word_array := split(bullet_array[Idx], " ");
WordCount := count(word_array);
For x := 1 To WordCount Do
(
new_bullet_text := new_bullet_text + word_array[x] + " ";
NewBulletLen := Length(new_bullet_text);
If x < WordCount then
(
If (NewBulletLen + Length(word_array[x+1]) - WrapLen) >= WrapLength then
(
WrapLen := NewBulletLen - Length(word_array[x+1]);
new_bullet_text := new_bullet_text + ChrW(13) + ChrW(9) + " ";
)
)
);
Bullet_text := Bullet_text + new_bullet_text;
)
);
Bullet_text := Replace(Bullet_text,"~", ChrW(13) + ChrW(13) + ChrW(9));
sentence_text := sentence_text + Bullet_text;

If TotalInputLength > BulletSectionEnd then
(
// Append any remaining text to the bulleted text
non_bullet_section := Mid({?determination_reasons}, BulletSectionEnd, (TotalInputLength - BulletSectionEnd)+1);
non_bullet_text := Replace(non_bullet_section, "=", ChrW(13));
non_bullet_text := Replace(non_bullet_text, "~", LineFeeds);
sentence_text := sentence_text + ChrW(13) + non_bullet_text;
)
)
else
(
sentence_text := sentence_text + Replace({?determination_reasons},"~", ChrW(13) + ChrW(13) + ChrW(9));
);

sentence_text := ChrW(13) + sentence_text;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top