Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: CR Processing Engine Post Reply Post New Topic
Page  of 2 Next >>
Author Message
freebird40CR
Newbie
Newbie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 9
Quote freebird40CR Replybullet Topic: CR Processing Engine
    Posted: 28 Nov 2012 at 6:45am
I am trying to display the RecaptureDonorYearDiff on the detail section of the report. It will display the GiftYear and PreviousGiftYear with no problem but when making the calculation the result for the RecaptureDonorDiff is equal to zero. For example, if GiftYear is 2010 and PreviousGiftYear is 2007, the difference should be 3. Listed below is the formula. The formula is placed in the detail section of the report.

Local NumberVar PreviousGiftYear := Year(Previous({CnGf_1.CnGf_1_Date}));
Local NumberVar GiftYear := Year({CnGf_1.CnGf_1_Date});

Local NumberVar RecaptureDonorYearDiff;

Local BooleanVar RecaptureDonor;

WhilePrintingRecords;

RecaptureDonorYearDiff = GiftYear - PreviousGiftYear;

If RecaptureDonorYearDiff >= 2 Then

    RecaptureDonor = True
Else
    RecaptureDonor = False
;

"RecaptureDonor:                  " + ToText(RecaptureDonor);
"Previous Gift Year:              " + ToText(PreviousGiftYear);
"Gift Year:                      " + ToText(GiftYear);
"Recapture Donor Year Difference: " + ToText(GiftYear) + " - " + ToText(PreviousGiftYear) + " = " + ToText(RecaptureDonorYearDiff);
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 29 Nov 2012 at 4:10am
"Previous" works for all records and you're not checking to see whether you're at the start of a group or the end of a group.  This will only work if you're at the end of a group.  Rather than trying to do all of this in a single formula, I would set up separate formulas, something like this (assuming your data is ordered by donation date and that you're grouping on donor):
 
{@PiorYear}
//If the donor has more than one donation date
If Previous({donor group field}) = {donor group field} then
  Year(Previous({CnGf_1.CnGf_1_Date}))
else //default to current year if there is no previous record
  Year({CnGf_1.CnGf_1_Date})
 
{@CurrentYear}
Year({CnGf_1.CnGf_1_Date})
 
{@RecaptureDonorYearDif}
{@CurrentYear} - {@PriorYear}
 
{@RecaptureDonor}
//this evaluates to True or False without the If
{@RecaptureDonorYearDif} >= 2
 
You can then test these formulas to see what the values are.  Then, instead of creating a formula to display the values with the headings, you have a couple of options:
 
1.  Create a separate text object on the report for each label then drag each of the formulas next to its corresponding label.  Format the numbers so that they don't show decimals (your "ToText" calls above, don't do that...)  This makes it very easy to line up the numbers vertically.
 
2.  Create a single text object on the report that contains all of the labels.  Drag the formulas into the text object so that they're embedded in it next to the appropriate label.  Select each formula, right-click, format the number to not have any decimals.
 
-Dell
 
IP IP Logged
freebird40CR
Newbie
Newbie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 9
Quote freebird40CR Replybullet Posted: 30 Nov 2012 at 4:24am
{@RecaptureDonorYearDif} formula is returning a Boolean value even though I declared RecaptureDonorYearDiff variable as a NumberVar.
 
 

Local NumberVar PreviousGiftYear := Year(Previous({CnGf_1.CnGf_1_Date}));
Local NumberVar GiftYear := Year({CnGf_1.CnGf_1_Date});
Local NumberVar RecaptureDonorYearDiff;

WhilePrintingRecords;

RecaptureDonorYearDiff = GiftYear - PreviousGiftYear;



Edited by freebird40CR - 30 Nov 2012 at 5:07am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 30 Nov 2012 at 5:02am
Change it to:
 
ptureDonorYearDiff := GiftYear - PreviousGiftYear;
IP IP Logged
freebird40CR
Newbie
Newbie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 9
Quote freebird40CR Replybullet Posted: 05 Dec 2012 at 3:09am
Thank you so much, it works! Why didn't it worked without the ":"?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 05 Dec 2012 at 3:30am
Originally posted by freebird40CR

Thank you so much, it works! Why didn't it worked without the ":"?
 
"=" is a boolean comparison.  ":=" is assignment.  Some programming languages work this way and this is the way that you work with variables in Crystal.
 
-Dell
IP IP Logged
freebird40CR
Newbie
Newbie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 9
Quote freebird40CR Replybullet Posted: 05 Dec 2012 at 4:19am
{@RecaptureDonor}
//this evaluates to True or False without the If
{@RecaptureDonorYearDif} >= 2
 
It did not work. All of the RecaptureDonor results are False.
IP IP Logged
freebird40CR
Newbie
Newbie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 9
Quote freebird40CR Replybullet Posted: 05 Dec 2012 at 5:45am

Thank you for the information.

IP IP Logged
freebird40CR
Newbie
Newbie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 9
Quote freebird40CR Replybullet Posted: 05 Dec 2012 at 6:03am
{@PiorYear}
//If the donor has more than one donation date
If Previous({donor group field}) = {donor group field} then
  Year(Previous({CnGf_1.CnGf_1_Date}))
else //default to current year if there is no previous record
  Year({CnGf_1.CnGf_1_Date})
 
Thank you, this worked like a charm.
IP IP Logged
freebird40CR
Newbie
Newbie


Joined: 28 Nov 2012
Online Status: Offline
Posts: 9
Quote freebird40CR Replybullet Posted: 14 Dec 2012 at 5:44am
It did not work for the FIRST record within the group.
IP IP Logged
Page  of 2 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.033 seconds.