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
<< Prev Page  of 3 Next >>
Author Message
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 18 Nov 2009 at 6:47am

local NumberVar bkglth := DateDiff('d',{table.Start Date},{Table.End Date});
local NumberVar i := 0;
local datetimevar array aDate;

Redim aDate[bkglth];
For  i:= 0 to bkglth do

(
aDate:= dateadd('d',i,{Table.Start Date});
);
 
The new error is "A subscript must be between 1 and the size of array"
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Nov 2009 at 6:56am
well, I said arrays weren't my forte... Unlike Basic, CR's array start at 1, not 0.
 
if you want the first array element to be the start date, change it to:
For  i:= 1 to bkglth do
(
aDate sq i sq:= dateadd('d',i-1,{Table.Start Date});
);
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 18 Nov 2009 at 7:03am

local NumberVar bkglth := DateDiff('d',{Table.Start Date},{Table.End Date});
local NumberVar i := 0;
local datetimevar array aDate;

Redim aDate[bkglth];
For  i:= 0 to bkglth do
(
aDate:= dateadd('d',i,{Table.Start Date});
);

Getting 2 errors now
 
1 - Array's dimension must be between 1 and 1000
2 - Subscript must be between 1 and array size
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 18 Nov 2009 at 7:10am
i think i may have figured out why i am getting those errors but i am still getting a True or a False for each date rather than the date value itself.
 
Do you know how i can show the array now?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Nov 2009 at 7:24am
Redim aDate[bkglth];
For  i:= 0 to bkglth do
(
aDate[i+1]:= dateadd('d',i,{Table.Start Date});
);
 
should help for the subscript, and if the dates are more than 3 years apart that would be the first error.
 
as for displaying the values, you could start with a simple formula:
shared datetimevar array aDate;
aDate[1]
 
it should display a date, hopefully the starting date...
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 18 Nov 2009 at 7:32am

local NumberVar bkglth := (If {Tbl.StartDate}={Tbl.End Date} then 1 else (Tble.End Date}-{Table.Start Date}));
local NumberVar i := 1;
local datetimevar array aDate;

Redim aDate[bkglth];
For  i:= 1 to bkglth do

(
aDate:= dateadd('d',i-1,{Tbl.Start Date});
);
 
i have changed the code a little bit so the array is not stuck at i=0 and I am not getting any errors now. However; it is returning a True/False and just one value.
 
I have tried aDate[1] and that does working giving me the Start Date which is good but as soon as I try aDate[2] or use aDate; it fails again.
 
Really appreciate all your help on this :):):)
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Nov 2009 at 7:41am
I would check what value bkglth has.  In some cases it is 1, so that is as high as you can go.  I would also check if table.End Date - Table.Start gives the value that you are expecting (table and ( are incorrect above, but I am guessing that they just typos)...the true/false is confusing.
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 18 Nov 2009 at 7:46am
You are right that in some cases bkglth is only 1 which is fine and I am getting the same value using a simple subtract operation between the 2 dates as I was getting with the Datediff and it is correct as what it should be between the dates.
 
I guess the last part is turning out to be the hardest where I need to figure out how to display the full array now rather than just one True/False
 
The TBL part does not matter as I am masking the original field names just for easy understanding.
 
Know any array experts here then??
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 18 Nov 2009 at 8:14am
displaying the entire array, is doable, but if you want to access them as a grouping variable or to use in a formula, it is going to be difficult, though not undoable, as I think about it....just not pretty.
 
to see the complete array in a textbox:
local numbervar ind;
shared datetimevar arr aDate;
local numbervar upInd;
local stringvar allDates;
 
upInd := uBound(aDate);
For ind := 1 to upInd Do
(
  allDate := allDates + totext(aDate[ind],"MM/dd/yyyy") + chr(13)+chr(10);
);
 
allDate
 
 
drag the formula onto your report and set it to Grow on.
 
HTH
 
 
 
IP IP Logged
asadiq
Newbie
Newbie


Joined: 16 Nov 2009
Online Status: Offline
Posts: 16
Quote asadiq Replybullet Posted: 18 Nov 2009 at 8:27am
Using this second formula is giving me an error to say " The ) is missing" but i cannot see where it is missing.
 
If I needed it to come out as a date array rather than a string; how complicated would that formula be then?
IP IP Logged
<< Prev 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.031 seconds.