?
Solved

Shared Variables

Posted on 2008-11-14
16
Medium Priority
?
300 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:lword
  • 7
  • 4
  • 3
  • +1
15 Comments
 
LVL 3

Expert Comment

by:Cootser
ID: 22967749
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
 
LVL 3

Expert Comment

by:Cootser
ID: 22968198
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 22969172
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
Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

 
LVL 77

Expert Comment

by:peter57r
ID: 22969900
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
 
LVL 3

Expert Comment

by:Cootser
ID: 22972328
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
 

Author Comment

by:lword
ID: 22987330
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 22987612
There is a trick to having a subreport have a page footer.

I'll try to find it.

mlmcc
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 1400 total points
ID: 22987639
0
 
LVL 3

Expert Comment

by:Cootser
ID: 22993599
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
 
LVL 3

Expert Comment

by:Cootser
ID: 23008649
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
 

Author Comment

by:lword
ID: 23009654
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 23010236
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
 
LVL 3

Assisted Solution

by:Cootser
Cootser earned 600 total points
ID: 23030293
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
 

Author Closing Comment

by:lword
ID: 31517021
Hey thank you guys for the responses. The solution worked great!
Thank you once again.
0
 
LVL 3

Expert Comment

by:Cootser
ID: 23037616
Great news, glad to help.  It was fun (almost!!!).  Big thanks to mlmcc for the pointers
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question