Link to home
Start Free TrialLog in
Avatar of JDL129
JDL129

asked on

I need to display a running total in VS2008 C# CR

Hey CR guys!!

I need to display a running total for each statement printed for a monthly statement period.
I have a beginning balance which should be added to an Item total for each transaction TYPE which could be 'CHG' which would always be positive, 'PAYMENT' which would always be a negative, or 'ADJUSTMENT' which could be either.  These would be totaled and printed at the bottom with a "Please pay this amount" label and then set to 0 for the next statement.

Thanks for your help!!
Jerry
Avatar of Mike McCracken
Mike McCracken

Try this idea.

I assume you have a group on the account number

In the report header add a formula
WhilePrintingRecords;
Global NumberVar MonthlyTotal;
""

In the group header add a formula to reset the total to the current balance
WhilePrintingRecords;
Global NumberVar MonthlyTotal;
MonthlyTotal := {CurrentBalanceField};
""

In the details calculate the total
WhilePrintingRecords;
Global NumberVar MonthlyTotal;
MonthlyTotal := MonthlyTotal + {ItemTotal};
""

IN the group footer to print the amount due
WhilePrintingRecords;
Global NumberVar MonthlyTotal;
MonthlyTotal

mlmcc
Avatar of JDL129

ASKER

mlmcc!!!
Thanks for the response!!

In the detail formula I need to evaluate the type of transaction to decide if the total is to be added or subtracted:

If {sp_Statement;1.TYPE} = "CHG" then
    MonthlyTotal := MonthlyTotal + {sp_Statement;1.ITEMPRICE};

If {sp_Statement;1.TYPE} = "PAYMENT" then
    MonthlyTotal := MonthlyTotal - {sp_Statement;1.ITEMPRICE};

If {sp_Statement;1.TYPE} = "ADJUSTMENT" then
    IF {sp_Statement;1.ITEMPRICE} > 0 THEN
        MonthlyTotal := MonthlyTotal + {sp_Statement;1.ITEMPRICE};
    IF {sp_Statement;1.ITEMPRICE} < 0 THEN
        MonthlyTotal := MonthlyTotal - {sp_Statement;1.ITEMPRICE};

This is what I need it to do but can't make it work.

Thanks,

Jerry
This does subtract a PAYMENT but doesn't add a CHG.
Are you sure there are charges?

Is ItemPrice always positive for charge and payment?

Does it handle adjustments correctly?

Did you copy and paste the formula from your report to here?

mlmcc
Avatar of JDL129

ASKER

mlmcc!!  Do you never sleep?  :)
There are charges but the type is "CHG" and they are always to be added to the monthlyTotal.
The PAYMENTS are always positive but should be subtracted from the MonthlyTotal.
The ADJUSTMENTS can be positive or negative and should be handled accordingly.
Yes I did post the formula I came up with but only for the detail.  The formula as is doesn't work.  I had to change the numbervar to currencyvar.  If I just do the PAYMENTS it will work but when I add CHG or ADJUSTMENTS I just get zeros.

Thanks for hanging in there with me!!

Jerry
I prefer the if then else if structure

Try it this way

WhilePrintingRecords;
Global CurrencyVar MonthlyTotal;
If {sp_Statement;1.TYPE} = "CHG" then
    MonthlyTotal := MonthlyTotal + {sp_Statement;1.ITEMPRICE};
Else If {sp_Statement;1.TYPE} = "PAYMENT" then
    MonthlyTotal := MonthlyTotal - {sp_Statement;1.ITEMPRICE};
Else If {sp_Statement;1.TYPE} = "ADJUSTMENT" then
    IF {sp_Statement;1.ITEMPRICE} >= 0 THEN
        MonthlyTotal := MonthlyTotal + {sp_Statement;1.ITEMPRICE};
    Else
        MonthlyTotal := MonthlyTotal - {sp_Statement;1.ITEMPRICE};
""

Do all types use the same field for the value?

mlmcc

SOLUTION
Avatar of James0628
James0628

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JDL129

ASKER

mlmcc!!
Thanks for the response!!  My CR doesn't like the else if.  When it hits the first Else If the error message says that the remaining text does not appear to be part of the formula.  It will run if I take out the Else's and just make 3 If statments but it appears to only run the last If statement because with PAYMENT as the last all of the CHG values are 0.00.  The odd thing though is that the group footer formula has the correct total.  Go figure???

James,
Good idea!!  You can tell I was never good at arithmetic.  :)

Jerry
Remove the ; before the elses

mlmcc
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JDL129

ASKER

Upping points!
Avatar of JDL129

ASKER

Thanks to both of you for the responses!!!!!!!!!!!!!  I hope the split is appropriate.

Jerry
You're welcome.  Glad I could help.

 James