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

Conditional Formulas 2

Status
Not open for further replies.

jbhsuman

Technical User
Nov 11, 2003
68
US
Using CR9

I am creating a formula to calculate an amount based on an aging category within a group. Each time the group changes I want to reset the calculation variable to zero so we can start at zero again with the next group.
Here is the structure

GH1
Code:
Global numberVar InsTot90 := 0;
Detail
Code:
numberVar InsTot90;

if {DATA12.DATE} = Over90Days then
    	insTot90 := InsTot90 + {DATA11.BALANCE};
GF1
Code:
WhilePrintingRecords;
		numberVar InsTot90;

In the report I am displaying the value of InsTot90 in the detail section to insure the formula is calculating correctly, this works. However, when I try to display the final value for this group variable in the GF I get a huge number that is not even close to the number calculated in the detail section of the report. This number does not change regardless of where I place the formula, it’s as if the value of this variable is being set somewhere and is not even being reset to zero in the next GH1 where I thought I was forcing the variable InsTot90 to reset to zero.

Any clues as to what I am doing wrong?
 
Just a thought: the first declaration may only be kicking in upon initialization of the report (first pass, as Crystal calls it). Try slapping a "whileprintingrecords" on it, also and see what happens.
 
All variables are assumed to be global unless otherwise declared. Try these formulas out:

In the group Header:
WhilePrintingRecords;
If Not InRepeatedGroupHeader then numberVar InsTot90 := 0;

In the detail section:
WhilePrintingRecords;
if {DATA12.DATE} in Over90Days then numbervar insTot90 := numbervar InsTot90 + {DATA11.BALANCE};

in the group footer:
WhilePrintingRecords;
numberVar InsTot90;


Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Thank you all for helping. I appreciate the support.

dgillz - Your solition worked. Would you mind helping me understand why your changes were necessary?

In GH1 -
Code:
If Not InRepeatedGroupHeader then numberVar InsTot90 := 0;

The "InRepeatedGroupHeader" I could not find a reference to this anywhere in CR help. Why is this needed?

You also have "WhilePrintingRecords" before executing each command. Is this absolutly necessary before every command? Would it be easier to write this in basix syntax to avoid having to add this command?

Thank you for your help.
 
you should use WhilePrintingRecords in all formulas using a given variable....this forces Crystal to the various calculations at the proper time.

With regards to InRepeatedGroupHeader....the formula you have in this header would be executed everytime the header is printed. Most of the time you might expect the header would be shown only once/page....no problem there....but if the Group split across 2 pages the group header would be executing twice....resetting your variable when you don't want it to happen...to prevent this you use the following statement in your formula

If Not inrepeatedGroupHeader then
(
do something;
do somethingelse;
);

This updates on a new header but not on a repeat.


Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Thank you everyone for your valuable advice.

Jim, thank you for your detailed explaination. Can you recommend any publications to read that would help with writing complex formula's and such?
 
Ken Hamady has a couple of great tools for expert formulas and techniques, check out his website
Also check out "Crystal Reports Version X, the Complete Reference" by George Peck. Just replace X with the version you are using.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top