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.
lwordAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CootserCommented:
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
0
CootserCommented:
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
0
mlmccCommented:
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
0
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

peter57rCommented:
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.
0
CootserCommented:
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
0
lwordAuthor Commented:
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 !
0
mlmccCommented:
There is a trick to having a subreport have a page footer.

I'll try to find it.

mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CootserCommented:
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
0
CootserCommented:
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
0
lwordAuthor Commented:
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?
 
0
mlmccCommented:
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
0
CootserCommented:
Hello

I have attached a rework of the earlier sample

What it does is, in Details > New Page After of the subreport test

if pagenumber = 1 then
remainder(recordnumber,33) = 0
else
remainder(recordnumber-33,44) = 0

and this creates a Page Break after line 33 on the 1st page and after 44 lines of the 2nd and subsequent pages

(There is still a bit of tidying to do but it illustrates the method fairly well - I hope!)

Best regards

Cootser
ReportNew.zip
0
lwordAuthor Commented:
Hey thank you guys for the responses. The solution worked great!
Thank you once again.
0
CootserCommented:
Great news, glad to help.  It was fun (almost!!!).  Big thanks to mlmcc for the pointers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.