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

Counter Variable in Subreport 1

Status
Not open for further replies.

kj27

Programmer
Mar 16, 2010
30
US
I have a variable (Global by default) in my subreport which basically increments based on a condition:

numberVar connectionsCtr:= 0;

if {HISTORY.TYPE} = some value
connectionsCtr := connectionsCtr + 1
else
connectionsCtr

The problem is that the variable only goes to 1 and doesn't really count the true occurances of the condition. If I change the scpe to Shared, the variable works perfectly...but I don't know of a way to reset it upon group change.

In theory, I could use a Running Total Field, but I don't know how to filter using my condition, and also how to use that field value in a normal variable (RT fields don't show up as selectable choices in the formula builder).

Thanks
 
Are you talking about resetting for groups within the subreport? Or are you placing the sub in a group and linking it on the groupfield?

You need to use a shared variable and/or "whileprintingrecords;" in order to accumulate across records. Your formula should be something like this:

whileprintingrecords;
shared numbervar connectionsCtr;
if {HISTORY.TYPE} = "some value" then
connectionsCtr := connectionsCtr + 1 else
connectionsCtr := connectionsCtr;

To reset it, use a formula like this in the main report in a section just prior to the one containing the sub (in GH1a if the sub is in GH1b):

whileprintingrecords;
shared numbervar connectionsCtr;
if not inrepeatedgroupheader then
connectionsCtr := 0;

-LB
 
Thanks as usual LB. Actually my criteria was wrong because I didn't have the right specs. The shared var. in the sub should really be:
shared numberVar hist_count := Count({history.entryID});

In the main report there are two groups. Within the second group's header (which is where the sub is), I will use hist_count as the denominator in a ratio calculation.

The value of the count comes through but is always off in the sense that the hist_count = 0 for the first listing. Then the second listing will have the first's hist_count...and so on.

So I guess this is an issue about the evaluation time for hist_count. If I could get the correct count at each listing, then I can calculate the ratio correctly.

Thanks.
 
It is off because you are referencing the shared variable in the wrong section. If the sub is GH2a, then you must do the calculation in GH2b to get the correct value.

-LB
 
That makes sense...and indeed it works as you wrote. So I guess there's no way to change the placement. All the subs and their output are in GH2A but this calculation will output in GH2B.

The last question (since this is now mostly working), is where the placement of the reset code will be. You wrote about the inrepeatedgroupheader...and I was wondering where to place this code. In the main report, I put this code in for hist_count. Then I place this field in GH2A (the level before it is used in GH2B)...and then in GH2B (where it is actually used). This sets hist_count = 0 each time.

Thanks.
 
Place the reset in GH2a, the sub in GH2b, and the calculation in GH2c. You can suppress GH2a. I'm assuming you want to show some of the subs or other fields in GH2b? If so, format it GH2b in the section expert to "underlay following sections". Then you can align the calculation in GH2c with the GH2b fields.

Another approach would be to make GH2b disappear and pass shared variables from all of the subs into into GH2c. Let me know if you want to do that instead.

-LB
 
Please bear with my ignorance as CR is my weakest skill. I just want to verify my understanding before the changing the report. Here's how I've set this up:

GH2a: Has about 20 subs including one with the following code:
shared numberVar hist_ctr := Count({...})

I think you're suggesting to move this and other subs to GH2b. Now in the main report, I should physically place the field (hist_ctr) in GH2a with just the reset code.

Then in GH2c, I can place the ratio calculation that uses the value of hist_ctr.

Thanks for your patience. I think I see the methodology, but just want to make sure.

 
If you insert a new GH#2 section, you can toggle it so it becomes GH#2a without moving the subs. You can either do this by dragging the gray area to the left of the new section to the top position while in design mode, or you can go into the section expert and use the arrow keys.

You should place the reset FORMULA in the GH#2a, not the field itself. You can suppress this section.

Yes, the calculation belongs in GH#2c.

-LB
 
That worked perfectly LB. Thank you very much for your patience with this - I learned quite a bit along the way. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top