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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formulas !

Status
Not open for further replies.

transient

Programmer
Aug 11, 2000
3
0
0
US
does anyone have more cr savy than I?<br>I'm just trying to do a conditional count:<br>if the PD0130 field is greater than 0 then increment, <br>but it just gives me either 0 or 1.<br><br>numberVar x := 0;<br>if {AccRec.PD0130}&gt;0 then<br>&nbsp;x := x+1;<br>x;
 
Is that a single formula?&nbsp;&nbsp;or three formulas separated by the semi-colon?&nbsp;&nbsp;<br><br>If it is a single formula, the reason you only get 0 or 1 is that you are resetting the variable x to 0 everytime the formula is run.&nbsp;&nbsp;You need to have a formula that resets the variable, a separate formula that increments the variable, and a third variable that displays the variable.<br><br>Formula 1:&nbsp;&nbsp;WhilePrintingRecords;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumberVar x:=0;<br>Formula 2:&nbsp;&nbsp;WhilePrintingRecords;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumberVar x;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If {AccRec.PD0130}&gt;0 then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x := x+1;<br>Formula 3:&nbsp;&nbsp;WhilePrintingRecords;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NumberVar x;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x
 
thanks, that was a good idea. And I even tried<br>to use a shared variable but to no avail.
 
The only benefit you would receive from the shared variable is the ability to pass it to and from subreports.&nbsp;&nbsp;Are you saying the above didn't work?&nbsp;&nbsp;If no, make sure you are careful where you place the Formula 1.&nbsp;&nbsp;It is resetting the value of X, thus if it is placed in any details, group headers or group footers before Formula 3 is displayed, it will set the value of x back to 0.&nbsp;&nbsp;If you don't want the value of x to ever reset, place it in the report header section.&nbsp;&nbsp;Formula 2 should be placed in the detail section, create a suppressed subsection of details if you like (I prefer that to keep it neat).&nbsp;&nbsp;And Formula 3 would be in the group or report footer where you want the formula displayed.
 
If you are using a single formula, note that you are setting it to zero every time, then adding either zero or 1 to it.&nbsp;&nbsp;The result will always be zero or 1.&nbsp;&nbsp;As Nilsen pointed out, you need to use multiple formulas. <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
Thanks Nilsen.<br>Actually this works by itself if I just have it<br>in the suppressed details and in the footer.<br><br>NumberVar x;<br>if {AccRec.PD130}&gt;0 then<br>&nbsp;x := x + 1;<br><br>Thanks again.
 
Be careful that your count is correct in the footer, as when the formula is placed it adds 1 to x.&nbsp;&nbsp;Thus, it will add 1 to x in each detail, then adds another 1 to x in the footer.&nbsp;&nbsp;You could end up with a count of 1 more than your actual count.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top