Min Problem Initializing Variable
Using ReportBuilder 10.09, Delphi 2007
I am having trouble calculating a Minimum value off a Variable in the detail
band (let's call it MyVar).
I drop a calc variable on the group footer band (let's call it Min), and set
its Timing to Calculate on Traversal and Reset on Group Start. In the Calc
Tab, I initialize this variable in ReportOnStartFirstPass to 99999 (is there
a better place to initialize it to a high value?). In MinOnCalc I have:
if Value>MyVar.Value then Value:=MyVar.Value;
One of the groups has only 7 items in it, and none of them are 0.00, yet my
Min.Value returns 0.00.
I've been playing around with different events for initializing and
different resets, etc., but I can't figure out what I am doing wrong.
Please offer some guidance.
I am having trouble calculating a Minimum value off a Variable in the detail
band (let's call it MyVar).
I drop a calc variable on the group footer band (let's call it Min), and set
its Timing to Calculate on Traversal and Reset on Group Start. In the Calc
Tab, I initialize this variable in ReportOnStartFirstPass to 99999 (is there
a better place to initialize it to a high value?). In MinOnCalc I have:
if Value>MyVar.Value then Value:=MyVar.Value;
One of the groups has only 7 items in it, and none of them are 0.00, yet my
Min.Value returns 0.00.
I've been playing around with different events for initializing and
different resets, etc., but I can't figure out what I am doing wrong.
Please offer some guidance.
This discussion has been closed.
Comments
Rather than using the variable value to keep track of the minimum value, try
creating a global variable to do so.
1. Inside the top right treeview in the Code workspace (tab), right click
and select "Module".
2. Select "Declarations" and add a new variable. (gMin: Double;)
3. Inside the MyVar.OnCalc event, update the value and keep track of the
minimum value in gMin.
Value := ;
if Value < gMin then
gMin := Value;
4. Finally in the OnCalc event of the Min variable set it's value to gMin.
Value := gMin;
You will need to initialize the value of gMin to something large at the
start of the report and every time the group breaks. Try initializing the
value in an early event such as the OnInitializeParameters and in the
GroupFooter.AfterPrint events.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Should I be concerned about doing other calculations like Sum or Avg without
using global variables?
Also, can you help me understand why I was having a problem? Why is it
necessary to create global variables for every field for which I want to
show a minimum value?
No you shouldn't need to worry about this. The workaround I gave was just
for this specific case.
Upon further investigation it is possible to calculate a minimum without the
use of the global variables.
The main issue is the initialization of the variable value. You can perform
the same operations without the global variable by initializing the Min
variable value inside the OnReset event as well as the GroupFooterAfterPrint
event.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
variable value in the GroupFooterAfterPrint.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com