We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

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

JDL129
JDL129 asked
on
Medium Priority
386 Views
Last Modified: 2012-05-11
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
Comment
Watch Question

Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
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

Author

Commented:
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.
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
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

Author

Commented:
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
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
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

CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
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
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Remove the ; before the elses

mlmcc
Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Upping points!

Author

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

Jerry
CERTIFIED EXPERT

Commented:
You're welcome.  Glad I could help.

 James
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.