Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Array - Sum of Arrays in Group Post Reply Post New Topic
Author Message
Mailman
Newbie
Newbie
Avatar

Joined: 21 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote Mailman Replybullet Topic: Array - Sum of Arrays in Group
    Posted: 06 May 2009 at 2:22am
Hi I have a formula which creates an array to store time elements for 52 weeks i.e. the array has 52 elements ,
 
Is it possible to achieve a running total for the first element in an array and place it in the group footer.
 
My array is as follows below.
 
Global NumberVar Array WeeklyHrs;   // This is in the report details
redim WeeklyHrs[Len({CT_EVENT.weeks})];
NumberVar i;
for i := 1 to Len({CT_EVENT.weeks}) do
(
    if Mid({CT_EVENT.weeks},i,1) = "y" then  
    WeeklyHrs := tonumber(DateDiff ("n", {CT_EVENT.start_time}, {CT_EVENT.end_time}))/60
    else WeeklyHrs := 0;
);
Sum (WeeklyHrs)
 
What I want to do is a running total of all the first elements in the array to see if in week 1 the hrs are over 25.
 
Many thanks  
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 06 May 2009 at 6:54am
I don't know, I don't use arrays very often, but in the assignment, wouldn't you want to access the array element like: WeeklyHrs :=...?
 
If all you want is the first week, why not create a shared variable? 
 
I use shared variables a lot...but it would seem that shared variables and arrays would be about the same.  Though you can't do aggregate functions on shared variables, and I am suspecting that you can't do them on user arrays either.
IP IP Logged
Mailman
Newbie
Newbie
Avatar

Joined: 21 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote Mailman Replybullet Posted: 06 May 2009 at 9:41am
Hi many thanks for reply tried setting array as shared variable but couldn't return array as result of a formula (was using the sum (field ,Group) clause). Ultimately I want to do a running total on the array elemnts .
 
e.g. Group Staff Name **Weeks   ["1","2","3","4","5"]**
       Mon  9:00 - 10:00    (array) ["2.5","0","2.5",".75","0"]
       Tue 11:30 - 12:00    (array) ["1.5","1","1.5","0","0"]
 
Group Footer                              ["4","1","4"".75","0"] ** Result want 2 achieve
 
This will then give me the totals for each week this person worked .
 
Hope this makes some sort of sense.
 
Again many thanks.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 07 May 2009 at 6:52am
Hmm... I see what you want, had to do some research....Brian's book has the answer, at least partially.
 
shared numbervar array hrWorked
 
this will 'save' an array in memory for use.
 
one problem that I see, and I could be wrong but I think that I have seen Brian post the same response, you are using a multidimensional array, and Crystal can only handle a one dimensional array. 
 
I don't think that I am seeing the correct picture of the raw data, as this seems to be a complex way to report on the data, and one that Crystal doesn't handle.
IP IP Logged
Mailman
Newbie
Newbie
Avatar

Joined: 21 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote Mailman Replybullet Posted: 08 May 2009 at 3:01am
Originally posted by lockwelle

Hmm... I see what you want, had to do some research....Brian's book has the answer, at least partially.
 
shared numbervar array hrWorked
 
this will 'save' an array in memory for use.
 
one problem that I see, and I could be wrong but I think that I have seen Brian post the same response, you are using a multidimensional array, and Crystal can only handle a one dimensional array. 
 
I don't think that I am seeing the correct picture of the raw data, as this seems to be a complex way to report on the data, and one that Crystal doesn't handle.
IP IP Logged
Mailman
Newbie
Newbie
Avatar

Joined: 21 Apr 2008
Location: United Kingdom
Online Status: Offline
Posts: 12
Quote Mailman Replybullet Posted: 08 May 2009 at 3:07am
Hi lockwelle it is definitely a complex problem .The reason I decided to do it this week is because I have a feild Event Duration (in hrs ) ,the other feild is week pattern which is a string e.g. YNNYYY (always 52 chars)
 
what I have down is used an aray to hold the combination of if Y in text string then this is say 1.5 hrs if no then 0 hrs so my array will give the output ["1.5","0","0","1.5","1.5","1.5"]
 
But as you say it maybe that crystal doesn't support this .
 
Many thanks for your reply .
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.031 seconds.