Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with triple formulas for accumulation of data

Status
Not open for further replies.

flepkows

Programmer
Jun 7, 2004
17
US
I have the following three formulas, I am trying to accomplish the following with them. The Names array is holding dates pulled from the Db, I want the DB record associated with the date that is closest to todays date. I am getting the date difference in seconds between these two dates and placing these values in another array. Then I am bubble sorting the array of data differences to get the smallest one in the first position. Once I have this done, I grab the Name element that has the same index as the smallest value of the date difference array. Is my syntax correct? Will these formulas return the correct data? Thanks in advance.

Group Header:

WhilePrintingRecords;
Global DateVar array Names;
"";

Details Section:

WhilePrintingRecords;
Global DateVar array Names;
NumberVar i := 1;
Redim Preserve Names[UBound(Names) + 1];
Names[UBound(Names)] := Date({Timeline.TransitionDate});

Group Footer:

Global DateVar array Names;
NumberVar array buffer;
NumberVar temp;
NumberVar i := 1;
NumberVar k := 1;
NumberVar j := 1;
NumberVar p := 1;

for i := 1 to UBound (Names) step 1 do
Redim Preserve buffer[UBound(buffer) + 1];
buffer[UBound(buffer)] := (DateDiff ("s",DateTime(Names) , CurrentDate ));
;
for k := 1 to UBound (buffer) step 1 do
if(k <> UBound(buffer)) then
for j := k+1 to UBound (buffer) step 1 do
if(buffer[k] > buffer[j]) then
temp := buffer[k];
buffer[k] := buffer[j];
buffer[j] := temp;

;
for p := 0 to UBound(Names) step 1 do
if(buffer[1] = (DateDiff ("s",DateTime(Names[p]) , CurrentDate ))) then
Names[p];
 
I forgot to mention, everytime I run the Report i get an error message saying that an index must be between 1 and the size of the array, it says the error is in the group footer formula. Thanks again
 
there is lots wrong with you formulas

first in the Group header

********
WhilePrintingRecords;
Global DateVar array Names;
"";
********

This really doesn't do anything Except define the array name on the first group value. On subsequent values you are just making the array bigger and bigger in the detail section.

Are you trying to reset the array with each group value??

In the detail section

*************
WhilePrintingRecords;
Global DateVar array Names;
NumberVar i := 1;
Redim Preserve Names[UBound(Names) + 1];
Names[UBound(Names)] := Date({Timeline.TransitionDate});
**************

What is the purpose of the NumberVar i ??? it is not used in the formula and is redefined in the footer formula.

in the footer section

**************
Global DateVar array Names;
NumberVar array buffer;
NumberVar temp;
NumberVar i := 1;
NumberVar k := 1;
NumberVar j := 1;
NumberVar p := 1;

for i := 1 to UBound (Names) step 1 do
Redim Preserve buffer[UBound(buffer) + 1];
buffer[UBound(buffer)] := (DateDiff ("s",DateTime(Names) , CurrentDate ));
;
for k := 1 to UBound (buffer) step 1 do
if(k <> UBound(buffer)) then
for j := k+1 to UBound (buffer) step 1 do
if(buffer[k] > buffer[j]) then
temp := buffer[k];
buffer[k] := buffer[j];
buffer[j] := temp;

;
for p := 0 to UBound(Names) step 1 do
if(buffer[1] = (DateDiff ("s",DateTime(Names[p]) , CurrentDate ))) then
Names[p];

***************

Lots of work here

1. If all other formulas are prefaced with "WhilePrintingRecords" this formula should be as well.

2. Your do-loop syntax is not correct

the first loop should be

for i := 1 to UBound (Names) step 1 do
(
Redim Preserve buffer[UBound(buffer) + 1];
buffer[UBound(buffer)] := (DateDiff ("s",DateTime(Names) , CurrentDate ));
);


the second loop should look like

for k := 1 to UBound (buffer) step 1 do
(
if(k <> UBound(buffer)) then
for j := k+1 to UBound (buffer) step 1 do
(
if(buffer[k] > buffer[j]) then
(
temp := buffer[k];
buffer[k] := buffer[j];
buffer[j] := temp;
);
);
);

the last loop...Are you trying to print out Names[] where the condition is satisfied?? You don't have a prayer with this part of the formula. You need to create a string variable and concatenate the correct values in the loop then display the result.

for p := 0 to UBound(Names) step 1 do
if(buffer[1] = (DateDiff ("s",DateTime(Names[p]) , CurrentDate ))) then
Names[p];

As far as your Error message is concerned this part of the formula is where the error is occuring since ther is NO ZERO ARRAY ELEMENT IN CRYSTAL and p := 0 on the first value.

But correct this and you still have those other errors and probably a few more as I look at it.



Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top