Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Extracting strings from Array in Subreport Post Reply Post New Topic
Author Message
MartinHalford
Newbie
Newbie
Avatar

Joined: 13 Aug 2009
Location: United Kingdom
Online Status: Offline
Posts: 19
Quote MartinHalford Replybullet Topic: Extracting strings from Array in Subreport
     Posted: 30 Jun 2015 at 9:23pm
I have in my Main report a formula using the following code:

stringVar Segments;
WhileReadingRecords;
Segments:=Segments + ({TableA.ColumnX}) + ","

This gives me an array something like Value1,Value2,etc. There may be any number of values, including none, 1, 2, or 3.

So in my subreport I have created another formula field of the same name (Segments) and pass in {?Pm-@Segments}, having previously linked the subreport to the main report via @Segments. If I display this in my subreport it gives me exactly what I expect - i.e. Value1,Value2,etc.

Now I need to extract each array element as an individual string so that I can use them in my record selection formula. For example, another Formula field using split({?Pm-@Segments},",")[1]

This works and returns the first string. However, I need to add a test to see if the array element really exists and if not substitute with some other text to avoid a run-time error.

So why does this not work:
if ubound({?Pm-@Segments}) = 3 then split({?Pm-@Segments},",")[1] else "N/A"

The argument for the Ubound function returns an error "An array is required here", yet the Split function deals only with arrays???

How can I perform this test on all my array elements?
Thanks!
IP IP Logged
MartinHalford
Newbie
Newbie
Avatar

Joined: 13 Aug 2009
Location: United Kingdom
Online Status: Offline
Posts: 19
Quote MartinHalford Replybullet Posted: 30 Jun 2015 at 9:35pm
Sorry - confusing typo corrected:

So why does this not work:
if ubound({?Pm-@Segments}) = 1 then split({?Pm-@Segments},",")[1] else "N/A"

Also if I change the code in the Main Report formula to:

stringVar array Segments;
WhileReadingRecords;
Segments:=Segments + ({TableA.ColumnX}) + ","

CR then complains that 'The result of a formula cannot be an array'. I'm very confused! I don't care whether I use an array or a simple string but it seems that the functions at my disposal to break either into its comma-delimited parts is stopping me.

Edited by MartinHalford - 01 Jul 2015 at 12:58am
Thanks!
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