DetailBeforePrint vs. OnCalc "error"
Surprising error (?) found using DetailBeforePrint to calculate running
totals:
RB Ent 7.02, Delphi6
Pseudo-code:
There are six Variables in the Detail Band. Three of them to receive the
current value of SOME_CALC, and three to maintain running column totals.
The columns are for three ranges of values of SOME_CALC (1-10, 11-20,
21-30). Either Variable1, Variable2, or Variable3 displays the current
value of SOME_FIELD, depending on the value of SOME_CALC. Variable1A,
Variable2A, and Variable2A display the running totals of SOME_FIELD;
The SELECT statement: SELECT SOME_FIELD, ( FIELD_X - FIELD_Y ) AS
SOME_CALC FROM SOME_TABLE.
DetailBeforePrint:
case SOME_CALC of
1..10: Variable1.value := SOME_FIELD;
Variable1A.value := Variable1A + SOME_FIELD;
11..20: Variable2.value := SOME_FIELD ;
Variable2A.value := Variable2A + SOME_FIELD;
21..30: Variable3.value := + SOME_FIELD;
Variable3A.value := Variable3A + SOME_FIELD;
The error/weirdness (only occurs in a multi-page report):
If, for example, the value of SOME_CALC for the first (detail band) line
of page three is 7, then Variable1.Value is 7. But the value of
Variable1A increases by 14. If the search parameters are changed, so as
to cause different detail records to be at the top of the pages of the
report, then those different detail records are the ones that get
incremented twice, instead.
In short: When using the DetailBeforePrint to keep a running total, the
running total is incremented TWICE by the value of the current detail
item when it is the first detail line on a new page.
The problem does not occur if I put the cumulative-balance tracking
code in the OnCalc event of those variables (Var_1A, Var1B, etc.),
instead of in DetailBeforePrint.
Should not the DetailBeforePrint code work? What am I missing?
Dennis McFall
totals:
RB Ent 7.02, Delphi6
Pseudo-code:
There are six Variables in the Detail Band. Three of them to receive the
current value of SOME_CALC, and three to maintain running column totals.
The columns are for three ranges of values of SOME_CALC (1-10, 11-20,
21-30). Either Variable1, Variable2, or Variable3 displays the current
value of SOME_FIELD, depending on the value of SOME_CALC. Variable1A,
Variable2A, and Variable2A display the running totals of SOME_FIELD;
The SELECT statement: SELECT SOME_FIELD, ( FIELD_X - FIELD_Y ) AS
SOME_CALC FROM SOME_TABLE.
DetailBeforePrint:
case SOME_CALC of
1..10: Variable1.value := SOME_FIELD;
Variable1A.value := Variable1A + SOME_FIELD;
11..20: Variable2.value := SOME_FIELD ;
Variable2A.value := Variable2A + SOME_FIELD;
21..30: Variable3.value := + SOME_FIELD;
Variable3A.value := Variable3A + SOME_FIELD;
The error/weirdness (only occurs in a multi-page report):
If, for example, the value of SOME_CALC for the first (detail band) line
of page three is 7, then Variable1.Value is 7. But the value of
Variable1A increases by 14. If the search parameters are changed, so as
to cause different detail records to be at the top of the pages of the
report, then those different detail records are the ones that get
incremented twice, instead.
In short: When using the DetailBeforePrint to keep a running total, the
running total is incremented TWICE by the value of the current detail
item when it is the first detail line on a new page.
The problem does not occur if I put the cumulative-balance tracking
code in the OnCalc event of those variables (Var_1A, Var1B, etc.),
instead of in DetailBeforePrint.
Should not the DetailBeforePrint code work? What am I missing?
Dennis McFall
This discussion has been closed.
Comments
When making calculations, such as a running total, it is only safe to use
the OnCalc event as this is the only event that essentially fires once per
record. The DetailBand.BeforPrint event fires multiple times per record and
therefore should not be used in calculations.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com