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!

simple counter which resets for each new group

Status
Not open for further replies.

newestrichard

Technical User
Apr 4, 2003
3
EU
a simple one this i know but my ability with crystal and Basic is somewhat, ahem, limited...

i've tried using the "Count" funtion in a "running total" (and fiddled around with resets but no luck as it counts as it sees the data in the database, i think)

if i use a simple formula...

Whileprintingrecords;
numbervar x;
if{field.NAME}={field.NAME}then
x:=x+1

it will count but obviously won't reset on a new group. how do i reset? this must be really obvious but if i heard anything back i'd be delighted.

(i've got 3 groups and am supressing the detail so i'm showing group footer 3 as each line in my report and i'd like a simple count, i'm using crystal 9 linked to an Access database)
 
In Crystal 8.5, a Running Total has a [Reset] section that can be set to reset for each group. I've always found it worked fine.

Madawc Williams
East Anglia, Great Britain
 
thanks madawc,

i thought i'd exhausted all the "evaluate" and "reset" options in running total, i'll try again, it cant be that tough.

thanks for you reply.

 
As mentioned, you can use a running total. What you must have forgotten to do was set the evaluation formula so that it didn't count every record in the database as you found.

If you clicked the "Use a formula" radio button under Evaluate, you could have entered {Field.X} = {Field.Y}, to ensure that it only counted when that condition was met. Additionally, clicking the "On Change of Group" radio button under Reset, and specifying your group would force the count to zero at group level.

You can also do it the way you've nearly done it in your post. All you need is a separate (suppressed) formula in your group header that says:

Whileprintingrecords;
numbervar x := 0;

All the best,

Naith
 
thanks Naith, thats got it, after a fashion.

i tried to get a formulae to trigger a count using the running totals but to no avail, i was trying count a record if it equalled my group split but no luck, i think my logic was confused.

the reset did work however it added 2 each time, i think the "Whileprintingrecords;" in both the 'counter formula' and the 'reset formula' is causing it to count twice? anyways, i changed the increment to add 0.5 so it works now! no-one will be any the wiser when i chuck them out as PDFs, i'll have a root through them later.

many thanks for your help.
 
Dude, that is not the answer. Anybody who maintains your reports after you will slag you off when they see that workaround. [wink]

Your variable should only be counting once, in one location. It sounds like your reset formula is actually resetting and adding to the variable rather than just resetting the value. All you would have, if you weren't using running totals, would be something like this:

\\@Reset Formula to be placed in your Group Header where you want the reset to take place.
WhilePrintingRecords;
NumberVar X := 0;

\\@Incrementing Formula to be placed in your details section
WhilePrintingRecords;
NumberVar X;
If {Field.X} = {Field.Y}
Then X := X + 1
Else X := X;

\\@Show Count Formula to be placed in the Group Footer where you want to see the count total.
WhilePrintingRecords;
NumberVar X;

That's it. There should be no other place that X is being incremented.

Good luck,

Naith
 
"Your variable should only be counting once, in one location."
This is true, but if you still have trouble (variable is counting somewhere else and you can't find it), change the name in the three formulas above to something definitely unique. This should eliminate any stray counting that's going on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top