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

whileReadingRecords vs WhilePrintingRecords 1

Status
Not open for further replies.

elibb

Programmer
Oct 22, 2001
335
MX
hi, can anyone tell me whats the difference between using
whileReadingRecords and whilePrintingRecords in a formula field?

im using CR9.2 in a vb6.0 applications, and i have a very strange problem, i use some formulas to calculate the GrandTotals, because there are some conditions and i need some subreport fields, and sometimes it is right, and sometimes its not, and every time i click on the refresh button it changes between two results (one is right, and one is wrong) im wondering if it has something to do with the while im using.. i have something like this:


in the group footer of my report:

Code:
WhileprintingRecords; 
shared currencyvar tot:=Sum ({VentasDetalle.Total}, {Productos.id})- shared currencyvar subTotal;
the shared variable subTotal, comes from a subreport.

then i have this, that keeps an acumulate of the totals of each group
Code:
WhilePrintingRecords;
shared currencyvar Acum:= Acum + shared currencyVar tot;


in my GrandTotal Field:
Code:
WhilePrintingRecords; 
shared currencyvar Acum;

is there anything wrong? im kind of new in using formular in CR..

thank You very much

Eli
 
Whenever you get different results on a refresh (not related to database changes) it's usually because you're not properly initializing shared variables.
 
Well first of all

WhileReadingRecords: occurs as records are read on the first pass you cannot do summary operations and frankly I have never really found a use for this function.

WhilePrintingRecords: occurs as the report is printed and I use this all the time...the only time I DON'T use it is in Summary operation formulas and Grouping formulas. You must be consistant IMHO. By using WhilePrintingRecords you retain total control as to when your formulas are evaluated...you don't leave it up to Crystal's logic.

as far as your formula problems go

*********************************
in the group footer of my report:
*********************************


you do not describe your report footer...is it many sections or are all these formulas lumped together?

this is important since you have dependancies here.... ALSO where is the subreport for the shared variables located??? The subreport MUST run first before shared variables can be used....this means the subreport should be in a section ahead of the formulas using the returned results....not in the same section.

*********************************
WhileprintingRecords;
shared currencyvar tot:=Sum ({VentasDetalle.Total}, {Productos.id})- shared currencyvar subTotal;

the shared variable subTotal, comes from a subreport.
*********************************


I would rewrite the formula like this...though I don't think it is a real problem as is

WhileprintingRecords;
shared currencyvar tot;
shared currencyvar subTotal;

tot := Sum({VentasDetalle.Total},{Productos.id})- subTotal;

tot;

It is a lot cleaner...and I am not sure how Crystal handles declaration and math manipulation at the same time.

The big question is where are the subreports that use "tot" and "subtotal"

The "subtotal" subreport should be in a section before this formula...and if "tot" is used in a subreport (otherwise it doesn't have to be shared) then that subreport must be in a section following this formula.

*********************************
then i have this, that keeps an acumulate of the totals of each group

WhilePrintingRecords;
shared currencyvar Acum:= Acum + shared currencyVar tot;
*********************************


ok...again I would rewrite it

WhilePrintingRecords;
shared currencyvar Acum;
shared currencyVar tot;

Acum := Acum + tot;

Acum;

There is a question here as to where this formula is located....if it is in the same section as the previous formula...How do you know this formula is evaluated second??? Answer...you don't!!

You must force Crystal to evaluate it at the proper time by changing your formula to

EvaluateAfter(@previousFormula);
shared currencyvar Acum;
shared currencyVar tot;

Acum := Acum + tot;

Acum;

Where @previousFormula is the formula above this one.

*********************************
in my GrandTotal Field:

WhilePrintingRecords;
shared currencyvar Acum;
*********************************


I don't see the purpose for this formula...the one above it does this job fine....but if it is in say a report footer then I would just change it slightly...again clarity more than anything

WhilePrintingRecords;
shared currencyvar Acum;

Acum;

I hope this helps you




Jim Broadbent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top