Tips and Tricks
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Tips and Tricks
Message Icon Topic: Date Increments - URGENT!! Post Reply Post New Topic
Page  of 3 Next >>
Author Message
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Topic: Date Increments - URGENT!!
    Posted: 16 Nov 2009 at 5:35am
Hi,
 
I need to work out how to print and increment all date values between 2 given dates using a For loop...
for example....
Date1 - 01/10/09
Date2 - 05/10/09
 
I need it to print
01/10/09
02/10/09
03/10/09
04/10/09
05/10/09


Edited by asadiq - 16 Nov 2009 at 5:38am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 17 Nov 2009 at 6:32am
local stringvar allDate;
local datevar aDate := {table.startDate};
 
While aDate <= {table.endDate}
Do(
  aDate := DATEADD("m",1,aDate);
  allDate := allDate + aDate +chrw(13) + chrw(10);
);
 
 
this will increment the date, but it will only print the last case.  In order to get the display, you would need to place it in a string variable, but then you will get them all in a one text box.
 
You might want to put them in an array at the start of the report and then use the array to group on (haven't done this, but it might be possible).
 
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 17 Nov 2009 at 8:38am
hi,
 
Thanks for your response.
However; I had that part worked out already using a For loop.
I am stuck on the last part where it returns only the last date after all the increments rather than printing each date within a range on a separate line. Basically need it to compile an array of dates using result from the For loop.
 
I cannot put them in an array at the start because the start and the end dates are not fixed dates. They are 2 fields in the database for example Date 1 and Date 2 which would be different for every record.
 
Hope I am making sense.
 
Thanks,
 
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 17 Nov 2009 at 8:51am
Sorry - I did not mention that I am working with Crystal 8.5
 
And i just tried your code to see how that works but it is not working.
Is chrw a function? Or what should that part be doing?
 
Thanks
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 17 Nov 2009 at 9:32am
chrw is a function...it is creating a crlf character.
 
since you are using an array and you know the enddate...I am thinking you know the number of iterations,
a) create the array, since you know the number of iterations.
b) aDate := DateAdd("m",i,{table.startDate});
  where i is the number of the iteration.  Since the array starts at 0, that could be the start date.
 
I would ignore the part about the updating of the allDate as it is a string.  You would want a shared datetimevar arr aDate.  I don't work with arrays, so my syntax might be off a bit.
 
HTH
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 17 Nov 2009 at 10:13am
I want to use an array on returned date values but I am not sure how to create an array from loop results....that is the part I am really stuck on.
 
I am using iterations but I am still getting just the last date at the end of the loop....
 
i need it to print the result of each iteration and build an array
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 17 Nov 2009 at 10:31am
I don't know the exact syntax but if you know the number of iterations you should be able to create the array.
 
It appears that the syntax is similar to:
shared datetimevar arr aDate;
local numbervar iter;  //set this to the number of iterations
local numbervar i;
 
Redim aDate[iter];
For i:=0 to iter Do
(
  aDate := dateadd("m",i,{table.startDate};
);
 
this will create an array that has the dates...if you want to see the values, that might be problematic as the number of array values is indeterminate, so you can't create an indeterminate number of formulas.  you might need to create a function or if there is an upper limit of the number you can use that.
 
Either way, the way to access the variable is
shared datetimevar arr aDate;
aDate;  //where i is the index that you are looking for.
 
Again, arrays are not my forte, hopefully, I am close enough for you to fill in the blanks.
 
HTH
 
 
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 18 Nov 2009 at 6:33am
hi,
 
This is the code i am using.
 
local NumberVar bkglth := DateDiff('d',{Table.Start Date},{Table.End Date});
local NumberVar i := 0;
shared datetimevar array aDate;
 
Redim aDate[bkglth];
For  i:= 0 to bkglth do
(
aDate:= dateadd("m",i,{Table.Start Date});
);
 
The error I am getting is "An array's dimension must be an integer between 1 and 1000"
 
Any ideas?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Nov 2009 at 6:36am
2 observations. 1) you are calculating the number of days between 2 dates and then adding the number of months.
2) you are not assigning the value to an array member but to the array, which is probably the cause of the error.
 
aDate := dateadd("m",i,{Table.Start Date});
should help
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Nov 2009 at 6:38am
how annoying... id should say
aDate  squareBracket i closeSquareBracket  := dateadd("m",i,{Table.Start Date});
 
evidently it is seeing the array assignment as a code to display italics.  Sorry for any confusion.

 
IP IP Logged
Page  of 3 Next >>
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.043 seconds.