Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Using Variable to Count

edited November 2012 in RAP
This is going to be a little hard to explain. I really need help.

I am trying to use a variable in the detail band to count records based
upon the value of certain fields. I'm not getting the result I would
get if I count the records manually.

The variable timing is set to calculate on Traversal and Reset on
ReportEnd. I am doing all the calculations inside the OnCalc event for
the variable, using mostly global variables for my calculations with If
Statements based upon certain values of fields within the record.

To troubleshoot my problem, I have this variable defined as a string
variable, and then I set its value when it is fired to a concatenation
of the record ID field being counted:
e.g., Value:=Value+IntToStr(ID)+' ';

I have it visible on the detail band directy beneath the row it is
counting.

The first three pages look fine, showing it to fire twice for two
records up to that point. Exactly as expected. However, on the fourth
page, all of a sudden it fires 3 times before it even gets to the next
record that should cause it to fire.

For example, the Value for the first line of the page shows:
1246 1262 1214 1219 1235

This begins on the first line for ID 1009, which should not fire the
OnCalc event at all (and doesn't because ID 1009 is not in the string
list).

As I look down the page, I see 1214 is the third record down. When it
gets to it, it adds another 1214 to the Value line (as expected).
1246 1262 1214 1219 1235 1214

The next line is ID 1219, and it gets added as well:
1246 1262 1214 1219 1235 1214 1219

And so on... As you can see, this is causing inflation of my numbers in
that it is counting record 1214 twice, 1219 twice, etc. I have been
pulling my hair out trying to figure out how to fix this so that each
record is counted only once. I checked the LookAhead, but that is not
set. I cannot figure out why between page 3 and 4 it is firing for
three of the records on the page before even checking the first record
on that page.

The data table is linked to another data table, and I thought this
might be causing the problem, but I cleared the link and it still
exhibits the problem.

Any advice on how I can use RAP to count records in the detail band in
a way that fires only once for each record traversed?


--

Comments

  • edited November 2012
    Hi David,

    When making numerical calculations, you need to be sure the datatype of
    the variable is set to a numerical one. This will ensure that your
    values stay consistent across pages.

    As a test, try setting your variable type to Integer or Double and see
    if that helps your results.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2012
    I only use the variable for calculations on global numerical variables
    and do not set the Value of the variable itself except for my debugging
    efforts. Interestingly, by changing the variable type to double and
    commenting out my debugging line of code that sets the Value, the final
    numbers of the global variables do change. I don't understand why, but
    it does. I think the numbers are still off, but it will take me some
    time to do a total count through the entire report to determine that
    for sure.

    One other thing is that I do set Calc Variables in the Summary Band
    within this single calc variable that is within the detail band. Would
    that be a problem?

    My main goal here is simply to count records based upon certain
    conditions and then set values in the summary band based upon those
    counts. I have tried different events and have read posts indicating
    that it should be done in a Calc Variable in the detail band. Please
    let me know if I am on the right track.


  • edited November 2012
    Hi Nico.

    I finished counting through the report, and the numbers are still
    inflated. How can I make sure the OnCalc event fires only once for
    each traversal of the record?

  • edited November 2012
    Hi David,

    Yes, this is the correct approach and if you would like to keep an
    accurate count based on the pipeline traversal, you need to be sure the
    data type of the variable is numeric. For caching purposes the OnCalc
    event fires differently for a String type.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2012
    Hi David,

    Which version of ReportBuilder and Delphi are you using? Are you able
    to recreate this with a simple example? If so, please send the example
    to support@digital-metaphors.com in .zip format and I'll take a look at
    it for you. Please be sure the example uses only native Delphi and RB
    components. If you need to send sample data, use TClientDatasets.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2012
    Hi Nico.

    Using Delphi 2007 with RB 14.06.

    It would be difficult for me to duplicate this in another generic app.
    The best I could do is provide you with my app and the data I am
    working with and let you run the report from that. However, if I could
    understand better how the events fire, I could probably figure this out
    for myself.

    I think I may have found a workaround that will take me some time to
    implement. It appears that if I duplicate the code in separate Calc
    variables placed in the summary band, that the numbers come up right.
    This will slow down the report in that multiple comparisons of the same
    type have to be done within each calc variable, but I think I may go
    ahead with this path.

    I have copied the code that I have placed in the calc variable in the
    detail band below. Maybe you can see something in it that might alert
    you to what the problem is.

    I notice that if I do a two pass report and set a Calc Variable in the
    detail band to one of the global variables, then move from the end of
    the report to the beginning of the report, the number gets greatly
    inflated. When the detail band gets to the record that is suppose to
    increase the variable by 1, it is instead increased by 30. However,
    another calc variable in the summary band getting set to the same
    global variable does not get inflated. I simply do not understand the
    events and what makes them fire.

    If you see the code below, I am simply trying to count records based
    upon the values of certain fields and then be able to see those values
    in the summary band. I thought I could do this in one of the events,
    like Detail BeforePrint or Detail BeforeGenerate, but this would not
    work. So I moved the code to a single calc variable called Variable1
    located in the Detail Band. All of the Calc Variables referred to in
    the code are located in the Summary Band, and they are set to fire on
    Traversal. I really want them to fire at the end of the report, but
    that did not seem to work at all. If you have any direction, I would
    appreciate it because I will likely have other reports like these to do.



    procedure Variable1OnCalc(var Value: Variant);
    begin
    if (Loans['CustNo']<>pCustNo) then {If Starting On New Customer}
    begin
    if (stNrRefisPerCust>0) then
    begin
    {Median Calculation}
    s1:=IntToStr(stNrRefisPerCust);
    stListOfRefisPerCust.Add(s1);
    {Value:=s1;}

    {Mode Calculation}
    if (stListCntRefisPerCust.Count>0) then
    begin
    {Find Previous Match For NrRefisPerCust}
    s2:='='+s1;
    i:=FindMatch(s2,stListCntRefisPerCust);
    if (i>0) then
    begin
    s2:=stListCntRefisPerCust[i];
    p:=pos('=',s2);
    if (p>1) then
    begin
    s2:=copy(s2,1,p-1);
    stCntRefisPerCust:=StrToIntDef(s2,0)+1;
    end
    else stCntRefisPerCust:=1;
    {Delete Previous Entry}
    stListCntRefisPerCust.Delete(i);
    end
    else stCntRefisPerCust:=1;
    end
    else stCntRefisPerCust:=1;
    s2:=IntToStr(stCntRefisPerCust)+'='+s1;
    stListCntRefisPerCust.Add(s2);
    stLastAdd:=s2;
    {Value:=stLastAdd+'/'+IntToStr(stListCntRefisPerCust.Count);}
    end; {if (stNrRefisPerCust>0) then}

    if (spNrRefisPerCust>0) then
    begin
    {Median Calculation}
    s1:=IntToStr(spNrRefisPerCust);
    spListOfRefisPerCust.Add(s1);
    {Mode Calculation}
    if (spListCntRefisPerCust.Count>0) then
    begin
    {Find Previous Match For NrRefisPerCust}
    s2:='='+s1;
    i:=FindMatch(s2,spListCntRefisPerCust);
    if (i>0) then
    begin
    s2:=spListCntRefisPerCust[i];
    p:=pos('=',s2);
    if (p>1) then
    begin
    s2:=copy(s2,1,p-1);
    spCntRefisPerCust:=StrToIntDef(s2,0)+1;
    end
    else spCntRefisPerCust:=1;
    {Delete Previous Entry}
    spListCntRefisPerCust.Delete(i);
    end
    else spCntRefisPerCust:=1;
    end
    else spCntRefisPerCust:=1;
    s2:=IntToStr(spCntRefisPerCust)+'='+s1;
    spListCntRefisPerCust.Add(s2);
    spLastAdd:=s2;
    end; {if (spNrRefisPerCust>0) then}

    if (itNrRefisPerCust>0) then
    begin
    {Median Calculation}
    s1:=IntToStr(itNrRefisPerCust);
    itListOfRefisPerCust.Add(s1);
    {Mode Calculation}
    if (itListCntRefisPerCust.Count>0) then
    begin
    {Find Previous Match For NrRefisPerCust}
    s2:='='+s1;
    i:=FindMatch(s2,itListCntRefisPerCust);
    if (i>0) then
    begin
    s2:=itListCntRefisPerCust[i];
    p:=pos('=',s2);
    if (p>1) then
    begin
    s2:=copy(s2,1,p-1);
    itCntRefisPerCust:=StrToIntDef(s2,0)+1;
    end
    else itCntRefisPerCust:=1;
    {Delete Previous Entry}
    itListCntRefisPerCust.Delete(i);
    end
    else itCntRefisPerCust:=1;
    end
    else itCntRefisPerCust:=1;
    s2:=IntToStr(itCntRefisPerCust)+'='+s1;
    itListCntRefisPerCust.Add(s2);
    itLastAdd:=s2;
    end; {if (itNrRefisPerCust>0) then}

    if (ipNrRefisPerCust>0) then
    begin
    {Median Calculation}
    s1:=IntToStr(ipNrRefisPerCust);
    ipListOfRefisPerCust.Add(s1);
    {Mode Calculation}
    if (ipListCntRefisPerCust.Count>0) then
    begin
    {Find Previous Match For NrRefisPerCust}
    s2:='='+s1;
    i:=FindMatch(s2,ipListCntRefisPerCust);
    if (i>0) then
    begin
    s2:=ipListCntRefisPerCust[i];
    p:=pos('=',s2);
    if (p>1) then
    begin
    s2:=copy(s2,1,p-1);
    ipCntRefisPerCust:=StrToIntDef(s2,0)+1;
    end
    else ipCntRefisPerCust:=1;
    {Delete Previous Entry}
    ipListCntRefisPerCust.Delete(i);
    end
    else ipCntRefisPerCust:=1;
    end
    else ipCntRefisPerCust:=1;
    s2:=IntToStr(ipCntRefisPerCust)+'='+s1;
    ipListCntRefisPerCust.Add(s2);
    ipLastAdd:=s2;
    end; {if (ipNrRefisPerCust>0) then}

    {Reinitialize For New Customer}
    stCustNewExt:=0;
    stNrRefisPerCust:=0;
    stRefiCntFlag:='';
    stRefiMCntFlag:='';

    spCustNewExt:=0;
    spNrRefisPerCust:=0;
    spRefiCntFlag:='';
    spRefiMCntFlag:='';

    itCustNewExt:=0;
    itNrRefisPerCust:=0;
    itRefiCntFlag:='';
    itRefiMCntFlag:='';

    ipCustNewExt:=0;
    ipNrRefisPerCust:=0;
    ipRefiCntFlag:='';
    ipRefiMCntFlag:='';

    RefiStatisticType:='';CustStatisticType:='';
    NewExt:=false;
    end; {If Starting On New Customer}
    if (Loans['LoanDate']>=qsDate) and (Loans['LoanDate']<=qeDate) then
    begin
    if (Loans['NrPmts']=1) then {S}
    begin
    if (Loans['SecurityItem']='T') then {ST}
    begin
    CustStatisticType:='ST';
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    stNrLoansAtEnd.Value:=stNrLoansAtEnd.Value+1;
    if (Pos(Loans['Status'],'SLBXD')>0) and
    ((Loans['SatisfyMethod']<>'R') and (Loans['SatisfyMethod']<>'F')) then
    {(Loans['NextLoanNo']=0)}
    begin
    stNrLoansClosed.Value:=stNrLoansClosed.Value+1;

    stSumLnAmtClosed.Value:=stSumLnAmtClosed.Value+Loans['LoanAmt'];
    end;
    stLnCnt:=stLnCnt+1; {Necessary Because stNrLoansTotal Includes
    Paydowns, Which Deflates Averages}
    stSumTerm.Value:=stSumTerm.Value+Loans['Term'];
    {ShowMessage('LoanNo: '+IntToStr(Loans['LoanNo'])+' CabFee:
    '+CurrToStr(Loans['CabFee'])+' MinCab: '+CurrToStr(stMinCabFee.Value)+'
    CabFeePer100: '+CurrToStr(CabFeePer100));}
    CabFeePer100:=Loans['CABFee']/(Loans['LoanAmt']/100);

    if (CabFeePer100stMaxCabFee.Value) then
    stMaxCabFee.Value:=CabFeePer100;

    stSumCabFee.Value:=stSumCabFee.Value+Loans['CabFee'];
    {+CabFeePer100;}
    stSumCabFeePer100:=stSumCabFeePer100+CabFeePer100;

    if (Loans['Status']='X') then stNrRepo.Value:=stNrRepo.Value+1;
    {Value:=IntToStr(stSumTerm.Value)+'/'+IntToStr(stLnCnt);}

    if (Loans['TimesRenewed']<=0) then
    begin
    NewExt:=True;
    stNrLoans.Value:=stNrLoans.Value+1;
    stSumLnAmt.Value:=stSumLnAmt.Value+Loans['LoanAmt'];
    stCustNewExt:=stCustNewExt+1;
    if (stCustNewExt<=1) then
    begin
    stNrCust.Value:=stNrCust.Value+1;
    {Value:=IntToStr(stCustNewExt);}
    end;
    end
    else
    begin
    RefiStatisticType:='ST';
    if (stCustNewExt<=1) then
    begin
    stNrRefisPerCust:=stNrRefisPerCust+1;
    {Value:=IntToStr(stNrRefisPerCust);}
    end;
    if NewExt then stNrRefi.Value:=stNrRefi.Value+1;
    stTotalNrRefis:=stTotalNrRefis+1;
    if NewExt and (stNrRefisPerCust=1) and (stRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    stNrCustRefi.Value:=stNrCustRefi.Value+1;
    stRefiCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    end;
    if NewExt and (stNrRefisPerCust=2) and (stRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    stNrCustRefiM.Value:=stNrCustRefiM.Value+1;
    stRefiMCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    {Value:=IntToStr(stNrRefisPerCust);}
    end;
    end;

    {Count Paydowns As Refis}
    if (Trans['NrRefis']>0) then {This Is Being Done In Addition To
    TimesRenewed Above To Add More Refis}
    begin {Assumes That All Paydowns Are
    Refis}
    stNrRefisPerCust:=stNrRefisPerCust+Trans['NrRefis'];
    if NewExt then
    stNrRefi.Value:=stNrRefi.Value+Trans['NrRefis'];
    stTotalNrRefis:=stTotalNrRefis+Trans['NrRefis'];
    if NewExt and (stNrRefisPerCust=1) and (stRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    stNrCustRefi.Value:=stNrCustRefi.Value+1;
    stRefiCntFlag:='Y';
    end;
    if NewExt and (stNrRefisPerCust=2) and (stRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    stNrCustRefiM.Value:=stNrCustRefiM.Value+1;
    stRefiMCntFlag:='Y';
    end;
    {Value:='p-'+IntToStr(stNrRefisPerCust);}
    end;
    end {ST}
    else
    begin {SP}
    CustStatisticType:='SP';
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    spNrLoansAtEnd.Value:=spNrLoansAtEnd.Value+1;
    if (Pos(Loans['Status'],'SLBXD')>0) and
    ((Loans['SatisfyMethod']<>'R') and (Loans['SatisfyMethod']<>'F')) then
    {(Loans['NextLoanNo']=0)}
    begin
    spNrLoansClosed.Value:=spNrLoansClosed.Value+1;

    spSumLnAmtClosed.Value:=spSumLnAmtClosed.Value+Loans['LoanAmt'];
    end;
    spLnCnt:=spLnCnt+1;
    spSumTerm.Value:=spSumTerm.Value+Loans['Term'];
    CabFeePer100:=Loans['CABFee']/(Loans['LoanAmt']/100);
    if (CabFeePer100spMaxCabFee.Value) then
    spMaxCabFee.Value:=CabFeePer100;
    spSumCabFee.Value:=spSumCabFee.Value+Loans['CabFee'];
    {+CabFeePer100;}
    spSumCabFeePer100:=spSumCabFeePer100+CabFeePer100;

    if (Loans['TimesRenewed']=0) then
    begin
    NewExt:=True;
    spNrLoans.Value:=spNrLoans.Value+1;
    spSumLnAmt.Value:=spSumLnAmt.Value+Loans['LoanAmt'];
    spCustNewExt:=spCustNewExt+1;
    if (spCustNewExt<=1) then spNrCust.Value:=spNrCust.Value+1;
    end
    else
    begin
    RefiStatisticType:='SP';
    if (spCustNewExt<=1) then
    spNrRefisPerCust:=spNrRefisPerCust+1;
    if NewExt then spNrRefi.Value:=spNrRefi.Value+1;
    spTotalNrRefis:=spTotalNrRefis+1;
    if NewExt and (spNrRefisPerCust=1) and (spRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    spNrCustRefi.Value:=spNrCustRefi.Value+1;
    spRefiCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    end;
    if NewExt and (spNrRefisPerCust=2) and (spRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    spNrCustRefiM.Value:=spNrCustRefiM.Value+1;
    spRefiMCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    end;
    end;
    {Count Paydowns As Refis}
    if (Trans['NrRefis']>0) then {This Is Being Done In Addition To
    TimesRenewed Above To Add More Refis}
    begin {Assumes That All Paydowns Are
    Refis}
    spNrRefisPerCust:=spNrRefisPerCust+Trans['NrRefis'];
    if NewExt then
    spNrRefi.Value:=spNrRefi.Value+Trans['NrRefis'];
    spTotalNrRefis:=spTotalNrRefis+Trans['NrRefis'];
    if NewExt and (spNrRefisPerCust=1) and (spRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    spNrCustRefi.Value:=spNrCustRefi.Value+1;
    spRefiCntFlag:='Y';
    end;
    if NewExt and (spNrRefisPerCust=2) and (spRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    spNrCustRefiM.Value:=spNrCustRefiM.Value+1;
    spRefiMCntFlag:='Y';
    end;
    end; {Count Paydowns As Refis}
    end; {Else (Loans['SecurityItem']<>'T') -- SP}
    end {if (Loans['NrPmts']=1) -- S}
    else {Else NrPmts>1}
    begin {I}
    if (Loans['SecurityItem']='T') then {IT}
    begin
    CustStatisticType:='IT';
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    itNrLoansAtEnd.Value:=itNrLoansAtEnd.Value+1;
    if (Pos(Loans['Status'],'SLBXD')>0) and
    ((Loans['SatisfyMethod']<>'R') and (Loans['SatisfyMethod']<>'F')) then
    {(Loans['NextLoanNo']=0)}
    begin
    itNrLoansClosed.Value:=itNrLoansClosed.Value+1;

    itSumLnAmtClosed.Value:=itSumLnAmtClosed.Value+Loans['LoanAmt'];
    end;
    itLnCnt:=itLnCnt+1;
    itSumTerm.Value:=itSumTerm.Value+Loans['Term'];
    CabFeePer100:=Loans['CABFee']/(Loans['LoanAmt']/100);

    if (CabFeePer100itMaxCabFee.Value) then
    itMaxCabFee.Value:=CabFeePer100;
    itSumCabFee.Value:=itSumCabFee.Value+Loans['CabFee'];
    {+CabFeePer100;}
    itSumCabFeePer100:=itSumCabFeePer100+CabFeePer100;

    if (Loans['Status']='X') then itNrRepo.Value:=itNrRepo.Value+1;

    if (Loans['TimesRenewed']=0) then
    begin
    NewExt:=True;
    itNrLoans.Value:=itNrLoans.Value+1;
    itSumLnAmt.Value:=itSumLnAmt.Value+Loans['LoanAmt'];
    itCustNewExt:=itCustNewExt+1;
    if (itCustNewExt<=1) then itNrCust.Value:=itNrCust.Value+1;
    end
    else
    begin
    RefiStatisticType:='IT';
    if (itCustNewExt<=1) then
    itNrRefisPerCust:=itNrRefisPerCust+1;
    if NewExt then itNrRefi.Value:=itNrRefi.Value+1;
    itTotalNrRefis:=itTotalNrRefis+1;
    if NewExt and (itNrRefisPerCust=1) and (itRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    itNrCustRefi.Value:=itNrCustRefi.Value+1;
    itRefiCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    end;
    if NewExt and (itNrRefisPerCust=2) and (itRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    itNrCustRefiM.Value:=itNrCustRefiM.Value+1;
    itRefiMCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    end;
    end;
    {Count Paydowns As Refis}
    if (Trans['NrRefis']>0) then {This Is Being Done In Addition To
    TimesRenewed Above To Add More Refis}
    begin {Assumes That All Paydowns Are
    Refis}
    itNrRefisPerCust:=itNrRefisPerCust+Trans['NrRefis'];
    if NewExt then
    itNrRefi.Value:=itNrRefi.Value+Trans['NrRefis'];
    itTotalNrRefis:=itTotalNrRefis+Trans['NrRefis'];
    if NewExt and (itNrRefisPerCust=1) and (itRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    itNrCustRefi.Value:=itNrCustRefi.Value+1;
    itRefiCntFlag:='Y';
    end;
    if NewExt and (itNrRefisPerCust=2) and (itRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    itNrCustRefiM.Value:=itNrCustRefiM.Value+1;
    itRefiMCntFlag:='Y';
    end;
    end; {Count Paydowns As Refis}
    end
    else
    begin {IP}
    CustStatisticType:='IP';
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    ipNrLoansAtEnd.Value:=ipNrLoansAtEnd.Value+1;
    if (Pos(Loans['Status'],'SLBXD')>0) and
    ((Loans['SatisfyMethod']<>'R') and (Loans['SatisfyMethod']<>'F')) then
    {(Loans['NextLoanNo']=0)}
    begin
    ipNrLoansClosed.Value:=ipNrLoansClosed.Value+1;

    ipSumLnAmtClosed.Value:=ipSumLnAmtClosed.Value+Loans['LoanAmt'];
    end;
    ipLnCnt:=ipLnCnt+1;
    ipSumTerm.Value:=ipSumTerm.Value+Loans['Term'];
    CabFeePer100:=Loans['CABFee']/(Loans['LoanAmt']/100);

    if (CabFeePer100ipMaxCabFee.Value) then
    ipMaxCabFee.Value:=CabFeePer100;
    ipSumCabFee.Value:=ipSumCabFee.Value+Loans['CabFee'];
    {+CabFeePer100;}
    ipSumCabFeePer100:=ipSumCabFeePer100+CabFeePer100;

    if (Loans['TimesRenewed']=0) then
    begin
    NewExt:=True;
    ipNrLoans.Value:=ipNrLoans.Value+1;
    ipSumLnAmt.Value:=ipSumLnAmt.Value+Loans['LoanAmt'];
    ipCustNewExt:=ipCustNewExt+1;
    if (ipCustNewExt<=1) then ipNrCust.Value:=ipNrCust.Value+1;
    end
    else
    begin
    RefiStatisticType:='IP';
    if (ipCustNewExt<=1) then
    ipNrRefisPerCust:=ipNrRefisPerCust+1;
    if NewExt then ipNrRefi.Value:=ipNrRefi.Value+1;
    ipTotalNrRefis:=ipTotalNrRefis+1;
    if NewExt and (ipNrRefisPerCust=1) and (ipRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    ipNrCustRefi.Value:=ipNrCustRefi.Value+1;
    ipRefiCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    end;
    if NewExt and (ipNrRefisPerCust=2) and (ipRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    ipNrCustRefiM.Value:=ipNrCustRefiM.Value+1;
    ipRefiMCntFlag:='Y'; {Necessary Because Of Paydowns Being
    Counted As Refis}
    end;
    end;
    {Count Paydowns As Refis}
    if (Trans['NrRefis']>0) then {This Is Being Done In Addition To
    TimesRenewed Above To Add More Refis}
    begin {Assumes That All Paydowns Are
    Refis}
    ipNrRefisPerCust:=ipNrRefisPerCust+Trans['NrRefis'];
    if NewExt then
    ipNrRefi.Value:=ipNrRefi.Value+Trans['NrRefis'];
    ipTotalNrRefis:=ipTotalNrRefis+Trans['NrRefis'];
    if NewExt and (ipNrRefisPerCust=1) and (ipRefiCntFlag='')
    then {Only Count Cust Once - Item No. 4}
    begin
    ipNrCustRefi.Value:=ipNrCustRefi.Value+1;
    ipRefiCntFlag:='Y';
    end;
    if NewExt and (ipNrRefisPerCust=2) and (ipRefiMCntFlag='')
    then {Only Count Cust Once If More Than One Refi - Item No. 5}
    begin
    ipNrCustRefiM.Value:=ipNrCustRefiM.Value+1;
    ipRefiMCntFlag:='Y';
    end;
    end; {Count Paydowns As Refis}
    end; {Else (SecurityItem<>'T') -- IP}
    end; {Else NrPmts>1}
    end {if (Loans['LoanDate']>=qsDate) and (Loans['LoanDate']<=qeDate)
    then}
    else
    if (Loans['LoanDate']<qsDate) and ((Loans['CloseDate']>=qsDate) or
    (Loans['CloseDate']=0) or (Loans['CloseDate'] Is Null)) then
    begin
    if (Loans['NrPmts']=1) then {S}
    begin
    if (Loans['SecurityItem']='T') then {ST}
    begin
    stNrLoansAtStart.Value:=stNrLoansAtStart.Value+1;
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    stNrLoansAtEnd.Value:=stNrLoansAtEnd.Value+1;

    {Value:=IntToStr(stNrLoansAtStart.Value)+'_'+FormatDateTime('m/d/yy',Loa
    ns['CloseDate']);}
    end
    else
    begin {SP}
    spNrLoansAtStart.Value:=spNrLoansAtStart.Value+1;
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    spNrLoansAtEnd.Value:=spNrLoansAtEnd.Value+1;
    end;
    end
    else {NrPmts>1}
    begin {I}
    if (Loans['SecurityItem']='T') then {IT}
    begin
    itNrLoansAtStart.Value:=itNrLoansAtStart.Value+1;
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    itNrLoansAtEnd.Value:=itNrLoansAtEnd.Value+1;
    end
    else
    begin {IP}
    ipNrLoansAtStart.Value:=ipNrLoansAtStart.Value+1;
    if (Loans['CloseDate']>qeDate) or (Loans['CloseDate']=0) or
    (Loans['CloseDate'] Is Null) then
    ipNrLoansAtEnd.Value:=ipNrLoansAtEnd.Value+1;
    end;
    end;
    end;
    pCustNo:=Loans['CustNo'];
    end;

  • edited November 2012
    Hi Nico.

    I think I finally found the trouble. The problem is caused by having a
    group with the "Keep Group Together" checked. By unchecking the Keep
    Group Together, I now do not get extra firing of the routine.

    Here's how I discovered what the problem was. I added a global variable
    to the start of the onCalc routine to count how many times the event is
    called. What I have noticed is that every time a new page started,
    that variable was always at least 1 higher than I expect it to be.
    Sometimes it indicated that the event had been called 7 times more than
    expected before getting to the first record printing on the page.

    Because the extra firing was always done before a new page was being
    printed, I began playing with the Group options, thinking it was
    related to header printing of some sort.

    Is this working as designed, or can it be fixed for a future release?
    It took me three days to find what the problem was, so I think it would
    be good if checking the Keep Group Together option does not result in
    extra calls to the OnCalc event of a Calc Variable in the detail band.

    --
  • edited November 2012
    Hi David,

    I created a simple test using the Biolife table of the DBDEMOS database
    with a KeepTogether group and a variable inside the summary band
    increasing its count on traversal. The result was correct with
    KeepTogether on or off.

    If possible, please create a simple example demonstrating an incorrect
    calculation similar to the one I created above and send it in .zip
    format to support@digital-metaphors.com.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.