Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Splitting a field Post Reply Post New Topic
Author Message
mrc161
Newbie
Newbie


Joined: 27 Dec 2007
Location: United States
Online Status: Offline
Posts: 19
Quote mrc161 Replybullet Topic: Splitting a field
    Posted: 28 Jan 2008 at 11:17am
Hello.  One of the tables I utilize has a field that has multiple pieces of data in it separated by commas.
 
So in other words, the field has the option of having up to 7 numbers, which would look like 1,2,3,4,5,6,7.
 
However, for each record, there may just be one or two, so each record would be different (one might be 1,2,3; another might be 2,4,7; etc, etc).
 
Each of these numbers has a corresponding description that I want to incorporate into a report, although the description is not actually included in any tables.
 
So if 1=No Memo; 2=No Source; 3=No Purchase, if the record has 1,2,3, I want it to reflect as "No Memo,No Source,No Purchase".  But if it is 1,3, I want it to reflect "No Memo,No Purchase."
 
Any way I can accomplish this without figuring out every possible combination between 1 through 7 and utilizing an if statement to plug the descriptions in?
 
Thanks!  Mike
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 28 Jan 2008 at 11:39am
I would use the Split() function to put the numbers into an array and then use the Choose() function to assign text to the string based upon the number. Here is a test function I wrote. Replace the test fields with your report fields and change the text in the Choose() function accordingly.
StringVar YourField;
StringVar Array ValueArray;
NumberVar ArrayIndex;
StringVar YourDescription;
YourField := "1,3,5";
//Trim that trailing comma because it adds an unnecssary extra element
YourField := Mid(YourField, 1, Len(YourField)-1);
ValueArray := Split(YourField,",");
For ArrayIndex:= 1 to UBound(ValueArray) Do
(
    YourDescription := YourDescription + Choose(Val(ValueArray[ArrayIndex]), "field1", "field2", "field3", "field 4", "field5") + ",";
);
//Trim the trailing comma
YourDescription := Mid(YourDescription, 1, Len(YourDescription)-1);

You can find out about these formulas and all the other Crystal Reports functions in Chapter 7, Writing Formulas, of my book Crystal Reports Encyclopedia.




Edited by BrianBischof - 28 Jan 2008 at 11:42am
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
mrc161
Newbie
Newbie


Joined: 27 Dec 2007
Location: United States
Online Status: Offline
Posts: 19
Quote mrc161 Replybullet Posted: 28 Jan 2008 at 12:14pm
Thank you.  I had tried playing around with both Split and Choose but wasn't getting anywhere with them so I will try this!  Mike
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.016 seconds.