Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: Split String Post Reply Post New Topic
Author Message
siweltj
Newbie
Newbie


Joined: 13 Sep 2007
Location: United States
Online Status: Offline
Posts: 16
Quote siweltj Replybullet Topic: Split String
    Posted: 15 Nov 2010 at 5:42am
I have a string field which contains any variation of the following data:
 
CLI1
 
CLI1,COM1,PCA1
CLI2,COM1,PCA1
CLI3,COM1,PCA1
CLI4,COM1,PCA1
CLI3
CLI2
CLI1
 
I need to split each section seperated by a comma into its own field.
 
I have tried:
Split ({Events.PassOnBoard},",")
but get "The results of a formula cannot be an array"
 
Any suggestions?
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 16 Nov 2010 at 1:59am
if ',' in {Events.PassOnBoard}
     then split({Events.PassOnBoard}, ',')[1]
          else {Events.PassOnBoard}
 
Use that for the first formula. Then for the others:
if ',' in {Events.PassOnBoard}
     then split({Events.PassOnBoard}, ',')[2]//or [3] for the last one
          else ''
|< /\ '][' ( )
IP IP Logged
siweltj
Newbie
Newbie


Joined: 13 Sep 2007
Location: United States
Online Status: Offline
Posts: 16
Quote siweltj Replybullet Posted: 16 Nov 2010 at 9:05am
Nearly perfect but I filter my report by date and some dates {Events.PassOnBoard} will contain only 2 variables within the field while other dates will contain up to 5 variables.  When running the third formula for the third variable:

if ',' in {Events.PassOnBoard}
     then split({Events.PassOnBoard}, ',')[3]//or [3] for the last one
          else ''

I get the following error:

"A subscript must be between 1 and the size of the array"


IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 17 Nov 2010 at 2:15am
Create a loop to count how many occurances of ',' there are and add 1 to determine how many variables there are. This formula was edited from something I found on this site that lockwelle created:
 
local numbervar iComma := instr({Events.PassOnBoard, ',');
local numbervar iCount:=0;
 
 while iComma <> 0 do
(
 if iComma <> 0 then iCount := iCount + 1;
 iComma:= instr(iComma + 1, {Events.PassOnBoard}, ",")
);
 
iCount;
 
Name it whatever you want, for this post it will be {CommaCount}.
 
Then you can create 5 formulas similar to this:
First Variable Formula
if not isnull({Events.PassOnBoard})
     then left({Events.PassOnBoard}, 4)
          else ''
//You can use this since the first one does not rely on a comma
//and since there may be no comma if only one variable.
 
Second Variable Formula
if ',' in {Events.PassOnBoard}
and {CommaCount}>0
     then split({Events.PassOnBoard}, ',')[2]
          else ''
 
Third Variable Formula
if ',' in {Events.PassOnBoard}
and {CommaCount}>1
     then split({Events.PassOnBoard}, ',')[3]
          else ''
 
And so forth.


Edited by FrnhtGLI - 17 Nov 2010 at 2:21am
|< /\ '][' ( )
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.047 seconds.