| Author |
Message |
asadiq
Newbie
Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
|

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
Edited by asadiq - 16 Nov 2009 at 5:38am
|
IP Logged |
|
|
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

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 Logged |
|
asadiq
Newbie
Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
|

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 Logged |
|
asadiq
Newbie
Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
|

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 Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

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 Logged |
|
asadiq
Newbie
Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
|

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 Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

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 Logged |
|
asadiq
Newbie
Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
|

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 Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

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 Logged |
|
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
|

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 Logged |
|
|
|