Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Result of split function Display in multiple rows Post Reply Post New Topic
Author Message
sravanthip
Newbie
Newbie


Joined: 03 Aug 2010
Online Status: Offline
Posts: 7
Quote sravanthip Replybullet Topic: Result of split function Display in multiple rows
     Posted: 07 Apr 2011 at 9:34pm
Hello,
I am working on Crystal reports Xi.I am creating one formula using split function.I have to display the result in multiple rows.Example:
If address has Multiple Lines split it based on Space(any delimiter)then display in differrent rows for particular row.
Like that i have container Numbers concatenated with &.I have display them in multiple rows one by one.
Here is my code:

whileprintingrecords;
Stringvar array ContCount:=split({XP_SeaContainer;1.ContCount},"&");
If (count(ContCount) =2) Then
ContCount[1] + Chr(13)+Chr(10)+ContCount[2]
else If (count(ContCount) =3) Then
ContCount[1] + Chr(13)+Chr(10)+ContCount[2] + Chr(13)+Chr(10)+ContCount[3]
else
ContCount[1]

The above working fine as static.But i want this code as Dynamic..
I tried using for loop but failed..Please tell me how can i make this as dynamic..

IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 08 Apr 2011 at 2:50am
Do you have the error message that tells you why it failed?

Your situation is pretty well set up for a loop.

If count = 1 then
   contCount[1]
else if count = 2 then
   contCount[1] + stuff + contCount[2]
else if count = 3 then
   contCount[1] + stuff + contCount[2] + stuff + contCount[3]
...

So clearly the loop variable will be the length of your array. For each iteration, you are simply appending more stuff to your final string.


local stringvar array contCount := split(...);
local stringvar outStr := ''; //initialize empty string
local numbervar length := count(contCount);
local numbervar x;

outStr := contCount[1];
for x := 2 to length do
   outStr := outStr & Chr(13)+Chr(10) & contCount[x];
outStr;


You may condense the code to save on resources if necessary. Note that although I don't do any error-checking, if the starting number for your for loop is greater than the end, it won't execute, so it is fine.

Edited by Keikoku - 08 Apr 2011 at 2:51am
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