Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Displaying data in ranges Post Reply Post New Topic
Author Message
sackett09
Newbie
Newbie


Joined: 29 Jan 2014
Online Status: Offline
Posts: 1
Quote sackett09 Replybullet Topic: Displaying data in ranges
     Posted: 29 Jan 2014 at 6:39am
I'm using a database field called PERMISSION.PER_NUMBER to return a list of permit numbers.  However, the list is quite long, and I was trying to find a way to condense the list.
 
For example, if the following numbers were listed in the details section of the report:
 
100
101
102
103
105
107
108
 
Is there a formula that could be written that could perhaps display it in ranges?
 
100-103
105
107-108
 
I appreciate any feed back on this.  Thank you.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 30 Jan 2014 at 5:22am
hmm...interesting request.

I think that you could do something like:
shared stringvar array permit;
shared numbervar lastIndex;
shared numbervar maxSize;
shared numbervar lastPermit;

if lastIndex + 1 >= maxSize then( // check and make sure the array is big enough
maxSize := maxSize + 10;
redim preserve permit[maxSize]
);

if {table.field} = lastPermit + 1 then( //sequential
lastPermit := {table.field};
)
else(
permits[lastIndex] := permits[lastIndex] + "-" + totext(lastPermit, 0, "");
lastIndex := lastIndex + 1;
permits[lastIndex] = totext({table.field}, 0, "");
lastPermit := {table.field}
);

this would be in the details section.

in the report header, or the group header, depends on what you have, you would have a reset formula like:
shared numbervar lastIndex := 0;
shared numbervar maxSize:=10;
shared stringvar array permit;
shared numbervar lastPermit := -1;
dim permit[maxSize];

in the report or group footer, you would need a display routine, to mimic what you had as a sample (also set this to Can Grow to accommodate an unknown number of lines):
shared numbervar lastIndex;
shared stringvar array permit;
local numbervar cur;
for cur=1 to lastIndex do(
permit[cur] + chrw(13) + chrw(10);
)


some of my syntax may be off, this is just off the top of my head. Dimensioning an array may be different as I have never done this myself. Arrays in Crystal are not overly helpful, but in htis case I think that they could be the solution.

The general idea is to create an array of strings. Store the first value of a 'run'. Then every time the next permit is in sequence update a counter. Where the numbers are not sequential, the write the range to the array and set the array for the next range.

It's an idea, hopefully it will lead to a solution.
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