[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 391
  • Last Modified:

Array Problem

I have the following formula, which calculates the number of days by taking the max and minimum dates from 5 dates and subtracts them from each other to work out number of days.

My problem is that I keep getting an error message saying size of array must be greater 0 and
Maximum(odates) is highlighted.

Can anybody help with this

Thanks


local numbervar i;
local numbervar j;
local datevar array idates := [{table.date1},{table.date2},{table.date3},{table.date4},{table.date5}];
local datevar array odates ;

for i := 1 to 5
do
(
    if idates[i] > date(0,0,0) then
    (
        j := j + 1;
        redim preserve odates[j];
        odates[j] := idates[i]
    )
);

Maximum(odates) - Minimum(odates)
0
polynominal
Asked:
polynominal
  • 2
  • 2
1 Solution
 
frodomanCommented:
As far as I know you can't apply the 'Maximum' function to an array - this function within Crystal takes the maximum from all of the values a recordset contains for a specific field.  I believe you're going to need to loop through your array and set the values there:

for i := 1 to 5
do
(
    if idates[i] > date(0,0,0) then
    (
        j := j + 1;
        redim preserve odates[j];
        odates[j] := idates[i]
        // ---------------- ADD LINES BELOW ----------
        if odates[j] > MaxDateSoFar then
           MaxDateSoFar := odates[j];
       if odates[j] < MinDateSoFar then
           MinDateSoFar := odates[j];
    )
);


The Max and Min are local variables that you'll want to set to some extreme values initially.  Finish your formula by subtracting the Min from the Max.
0
 
mlmccCommented:
Agree

mlmcc
0
 
polynominalAuthor Commented:
Thanks for the answers, I have changed the code as below and get the message the ) is missing, if is highlighted

local numbervar i;
local numbervar j;
local datevar array idates := [{table.date1},{table.date2},{table.date3},{table.date4},{table.date5}];
local datevar array odates ;

for i := 1 to 5
do
(
    if idates[i] > date(0,0,0) then
    (
        j := j + 1;
        redim preserve odates[j];
        odates[j] := idates[i]
     
        if odates[j] > MaxDateSoFar then
           MaxDateSoFar := odates[j];
       if odates[j] < MinDateSoFar then
           MinDateSoFar := odates[j];
    )
);

MaxDateSoFar - MinDateSoFar
0
 
mlmccCommented:
If the code is pasted from the formula then you are missing a ; on

        odates[j] := idates[i]

You might also want to delete the ; before the first )

If that doesn't work then maybe you need a ; after the first )

mlmcc
0
 
frodomanCommented:
You do need the semicolon after

  odates[j] := idates[i];

Also need it after the second to last ).  Correct syntax should be:

local numbervar i;
local numbervar j;
local datevar array idates := [{table.date1},{table.date2},{table.date3},{table.date4},{table.date5}];
local datevar array odates ;

for i := 1 to 5
do
(
    if idates[i] > date(0,0,0) then
    (
        j := j + 1;
        redim preserve odates[j];
        odates[j] := idates[i];
     
        if odates[j] > MaxDateSoFar then
           MaxDateSoFar := odates[j];
       if odates[j] < MinDateSoFar then
           MinDateSoFar := odates[j];
    );
);

MaxDateSoFar - MinDateSoFar
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now