Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Novice question re: building total then grand total

Status
Not open for further replies.

diamondtektips

Programmer
Nov 18, 2003
6
CA
Guys, I'm embarrased b/c I'm at least an intermediate programmer in VB, C++ and other lang but i'm such a lowly novice @ crystal... Your help is greatly GREATLY appreciated.
I have a A/R report which requires a margin calculation per company, and a final total for margin at the end of the report. Here is the code for the "@margin" field per company:
--------------
WhilePrintingRecords;

if {vr_08611.Past03} > 0 then
// if the value in 90 days is greater than 10% of the total
if (Sum ({vr_08611.Past03}, {@GrpCustIDName})) > ((Sum ({vr_08611.NewCur}, {@GrpCustIDName})+Sum ({vr_08611.Past01}, {@GrpCustIDName})+Sum ({vr_08611.Past02}, {@GrpCustIDName})+Sum ({vr_08611.Past03}, {@GrpCustIDName})+Sum ({vr_08611.Over03}, {@GrpCustIDName})) * 0.10) then
// return 0
0
else

// return total - 90 days
((Sum ({vr_08611.NewCur}, {@GrpCustIDName})+Sum ({vr_08611.Past01}, {@GrpCustIDName})+Sum ({vr_08611.Past02}, {@GrpCustIDName})+Sum ({vr_08611.Past03}, {@GrpCustIDName})+Sum ({vr_08611.Over03}, {@GrpCustIDName})) - (Sum ({vr_08611.Past03}, {@GrpCustIDName})))

else
// return 0
0

--------------

i coded it this way b/c i couldn't figure out how to use the built in functions like "sum", etc.
Now, if I use Crystal's Summary feature it tells me it can't create this summary field.
So I inserted a variable definition in the previous header, then tried to add to the variable every time the margin was calculated but i can't figure out how to insert another line into the nested else (Usually in VB you use {} but crystal expects a field if i use {}'s.)
Thus if you can tell me how to build a running total, i.e. how to define a shared var, how to insert summation code into the above nested else, and how to display the doggoned thing... I would be eternally greatful and will mow your lawn...
 
In Crystal, you need to use parenthesis not encapsulate the nested if statement, but why not simplify the statement to just have one if?
Code:
WhilePrintingRecords;

if {vr_08611.Past03} > 0 AND 
    Sum ({vr_08611.Past03}, {@GrpCustIDName}) <= 
  ((Sum ({vr_08611.NewCur}, {@GrpCustIDName}) + 
    Sum ({vr_08611.Past01}, {@GrpCustIDName}) +
    Sum ({vr_08611.Past02}, {@GrpCustIDName}) +
    Sum ({vr_08611.Past03}, {@GrpCustIDName}) +
    Sum ({vr_08611.Over03}, {@GrpCustIDName})) * 0.10) then
           // return total - 90 days
          ((Sum ({vr_08611.NewCur}, {@GrpCustIDName}) +
            Sum ({vr_08611.Past01}, {@GrpCustIDName}) +
            Sum ({vr_08611.Past02}, {@GrpCustIDName}) +
            Sum ({vr_08611.Past03}, {@GrpCustIDName}) +
            Sum ({vr_08611.Over03}, {@GrpCustIDName})) - (Sum ({vr_08611.Past03}, {@GrpCustIDName})))
else
    // return 0
    0

~Brian
 
thanks, that helped a little... i see that i was intending on incorrectly trying to return a value AND add to a running total... back to the drawing, er, keyboard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top