Link to home
Start Free TrialLog in
Avatar of lword
lword

asked on

Shared Variables

I have a subreport which runs into pages. Now for the records that has an asterisk, I have to display a text in the page footer.  I tried using a shared variable in the subreport and used that variable in the main report so  that I can suppress the text whenever the asterisk is not there in the page. But the variable in the main report is always displayed as 0.
Avatar of Cootser
Cootser

Hello

In the subreport create a formula

for example:
whileprintingrecords;
shared numbervar tstar;
if {table.field} like "*" then tstar := 1 else tstar := 0

place this in the footer of the subreport

then in the main report you can access the shared variable tstar

for example:
whileprintingrecords;
shared numbervar tstar;

every time you need to use the shared variable  you need to declare it, as above
whileprintingrecords; - this tells crystal to create / use the variable during rpt runtime

Hope this helps

Best regards

Cootser
I've had a rethink on this one...

Firstly, the formula to evaluate whether or not your field contains a star (*) needs to be in the details section of the sub report (if that is where the field to be evaluated is)

If record one contained a star the formula would evaluate to tstar = 1.  But if the next record  did not contain a star then the formula would evaluate to tstar = 0.  

The subreport would only return tstar = 1 if the final record in the subreport contained a star.

So, the formula to be placed in the subreport should be:

whileprintingrecords;
shared numbervar tstar;
if {table.field} like "*" then tstar := 1


tstar will be set to 1 if the field in any record (first, second or last) in the subreport contains a star
Avatar of Mike McCracken
You may need to declare the shared variable in the main report header.

Not sure if the value is changed until the subreport is done.

mlmcc
Copied from linked Q...

I don't think that  this is possible.  In my experience the communication between subreports and main reports is not precise enough for the main report to respond to page breaks in the subreport.
I think that to get values into the page footer, you would have to see if you could use a grouped report instead of a subreport.

Someone else might feel differently.
Hello

peter & michael are correct, of course.  there is no real easy way to get from the sub report back to the main report at the end of a sub report page.

Could lword count lines in the sub report and display a section, in the subreport, after every n lines that would imitate the page footer?

I will try something like that out, but right now i dont have a working example
Avatar of lword

ASKER

I had tried the above options already. The formula evaluates only at the end of the subreport. But I want the formula to be passed to the main report at the end of each subreport page. For e.g. if the subreport has 20 pages, and if there is an asterisk in the second page then the text should be shown in the footer of the second page alone, in the third page if there is no asterisk it should suppress the text. At present I have placed the text in the main report's footer. Is there a way out? It's very urgent !
There is a trick to having a subreport have a page footer.

I'll try to find it.

mlmcc
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent work, Holmes, er I mean michael.

I could not find that one myself and could not get my own test case to work  - i will try this solution at home

Very useful indeed

Thanks
Hello

I may have a solution for this one.

I have tested this a little bit but must admit i need to hit the hay (junors to feed in the wee hours - sleep at a premium)

I am attaching a sample report and spread sheet

In the sub report have a look at the way there are 3 details sections
The text in Details b is being suppressed based in the value of the shared variable test
test is cleared in details c

you would need to play with the field sizes to get the paging right but i think the principle is correct

I had the same hassle as lword seemed to refer to in his latest post - the variable always seemed to be on or off.  Until i added the details c section.

This may not be the final solution to this but i hope that it helps in some way
ReportTest.zip
Avatar of lword

ASKER

Wow... Great... I tried that option. It worked. Thank you so much for your help. I came across one thing when I tried this solution. I gave the formula across the 3 sections as mentioned in the link.
if(pagenumber = 1)then
Remainder(RecordNumber, 33) = 0
else
Remainder(RecordNumber, 44) = 0
Because my first page has header hence reduced the records in the first page alone. Now my first displays 33 records. And my second page displays only 11 records. From the third it displays 44 records correctly. Could you tell me the cause and how to rectify it?
 
You displayed 33 records on the first page then change to using 44 as the divisor.  11 records later the remainder is 0.

Rather than using the RecordNumber Field fou might use a formula that counts the records.
In the page header add a formula
WhilePrintingRecords;
Global NumberVar MyRecordCount;
MyRecordCount := 0;

In the detail section
WhilePrintingRecords;
Global NumberVar MyRecordCount;
MyRecordCount := MyRecordCount + 1;

Change your NEW PAGE formula to
WhilePrintingRecords;
Global NumberVar MyRecordCount;
if(pagenumber = 1)then
Remainder(MyRecordCount, 33) = 0
else
Remainder(MyRecordCount, 44) = 0

mlmcc
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lword

ASKER

Hey thank you guys for the responses. The solution worked great!
Thank you once again.
Great news, glad to help.  It was fun (almost!!!).  Big thanks to mlmcc for the pointers