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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Else missing!?!?!?!

Status
Not open for further replies.

ScottWood

Technical User
May 31, 2001
81
0
0
GB
Ive created an Array, i cant see anything wrong with the formula:

WhilePrintingRecords;
DateVar Array PreDel;
NumberVar Counter;

If Counter=2 then
PreDel:={OR_RECEIPT.TRANS_DATE}

but it keeps insisting that "The word ELSE is missing". The only information i want added to the array is if the counter equals 2. Anyone know how i can get around this?

Thanks
 
hi
Create your fomula as above
If Counter=2 then
PreDel:={OR_RECEIPT.TRANS_DATE}
else
" "

cheers


pgtek
 
You could try the following. (I'm assuming that you have defined counter in another formula, since here it isn't incrementing.)

WhilePrintingRecords;
DateVar Array PreDel;
NumberVar Counter;

If Counter = 2 then
PreDel[counter] := {OR_RECEIPT.TRANS_DATE}

-LB
 
lbass,

Thanks thats worked, the only problem ive got now though is, im trying to view the second element in the array, this is in the group header, as the counter is reset every time there is a new goup, but the result is just blank, here is my formula:

DateVar Array PreDel;
NumberVar Counter;

PreDel[2];

Thanks

 
Scott:

Maybe you didn't post it but where are you declaring your array? Do you only ever need the second element of the array? If so, you may not even need an array.

Can you post all your formulas that use the PreDel array and the Counter, and also tell us which section in the report that they reside in?

~Brian
 
Hi,

Yes i only need the second elemtent of the array. Here are my formulas:

@Counter
WhilePrintingRecords;
NumberVar Counter;

If {OR_RECEIPT.TRANS_DATE}=Next({OR_RECEIPT.TRANS_DATE}) then
Counter:=Counter+0;
If {OR_RECEIPT.TRANS_DATE}<>Next({OR_RECEIPT.TRANS_DATE}) then
Counter:=Counter+1;

The Counter is positioned in the detail section.

@Initalize
DateVar Array PreDel;
NumberVar Counter;

Redim PreDel[1000];
Counter:=0;

The Initalize formula is in the report header.

@Reset
WhilePrintingRecords;
NumberVar Counter;

Counter:=0;

The reset formual resides in the group header. I take it i also need to reset the array in the group header?

Thanks
 
For some strange reason its partly working now!?!?! although there is still a problem, the array now displays the second element in the group header, although it is showing the element from the previous group?

-Scott
 
I would drop the Array since you are only populating one value. You can just a normal date variable for this.

@Initalize
Code:
WhilePrintingRecords;
DateVar PreDel;
NumberVar Counter;

PreDel := Date(&quot;01/01/1900&quot;);
Counter := 0;
Move this to the group header.

@Counter
Code:
WhilePrintingRecords;
DateVar PreDel;
NumberVar Counter;

If {OR_RECEIPT.TRANS_DATE}=Next({OR_RECEIPT.TRANS_DATE}) then
    Counter:=Counter+0
Else
    Counter:=Counter+1;

If Counter = 2 then
    PreDel = {OR_RECEIPT.TRANS_DATE};

PreDel;
Leave this in the Detail Section and Suppress it.

@Display
Code:
WhilePrintingRecords;
DateVar PreDel;

PreDel;
Put this in the Group Footer. You will want to conditionally suppress this field if the value equals 01/01/1900.

This will get the result your are looking for in the Group Footer only.
If you need the result to be in the Header, @Counter will need to be changed.
You cannot use the Next or Previous Functions and still get the result into the Header.

~Brian
 
If you are trying to capture the second earliest date in a group, you could just insert a summary on the date field using NthSmallest, N = 2. Then drag this value from the group footer to the group header. If you are trying to get the second to the most recent date, then use NthLargest, N = 2.

-LB
 
lbass,

Ive just tried to use the NthLargest formula, it works, but the only problem is i have in some groups two dates which are the same, is there a way to ignore a record if it already exists in that group?

My counter did this, the records were sorted by date, and if the next date was the same as the previous, then the counter wouldnt increment.

Thanks
 
You could try the following:

if NthLargest(1,{table.date},{table.groupfield}) <>
NthLargest(2,{table.date},{table.groupfield}) then
NthLargest(2,{table.date},{table.groupfield}) else

if NthLargest(1,{table.date},{table.groupfield}) =
NthLargest(2,{table.date},{table.groupfield}) and
NthLargest(2,{table.date},{table.groupfield}) <>
NthLargest(3, {table.date}, {table.groupfield}) then
NthLargest(3, {table.date}, {table.groupfield}) else

if NthLargest(2,{table.date},{table.groupfield}) =
NthLargest(3, {table.date}, {table.groupfield}) and
NthLargest(3,{table.date},{table.groupfield}) <>
NthLargest(4, {table.date}, {table.groupfield}) then
NthLargest(4,{table.date},{table.groupfield})

You would have to adapt this formula to accommodate the maximum number of repeat dates that you think might be possible. The only advantage of this formula is that you can put it in the group header. If there is no limit to repeat dates, you should use Brian's formula in the group footer. Otherwise, to get the results in the group header you would need to do a subreport, use Brian's formula in the subreport, and display the group footer of the subreport in the group header of the main report.

-LB
 
There could be any amount of repeats, which is the problem, ive now managed to get the report to work with the arrays, so cheers guys.

-Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top