Solved

Crystal Report Shared Variable bring 0s

Posted on 2011-09-15
8
320 Views
Last Modified: 2012-05-12
I have a sub reports named sub_1. I got the sum value and created an shared variable [sum], and try to bring back to the main report and put in the detail section.

Sub_report->[Share_Variable_ Prior_Lease_Year_Sales]
shared NumberVar Prior_Lease_Year_Sales={sum}

Mian report->[Share_Variable_ Prior_Lease_Year_Sales]
WhilePrintingRecords;
shared NumberVar Prior_Lease_Year_Sales;
Prior_Lease_Year_Sales;

I put the shared variable in the detial section of main report  and link them by [sale_id]
1. I found out the first value of share variable always gives 0. which the actual value is not 0. and also realize that the correct value always offset one row.
2. Also, If the there is no value return from the subreport shared variable, then in the main report, that record willl read the previous's share variable's value. I want to see 0 if there is no value return.

How can I fix issue 1 and 2.

Thanks in advance!
0
Comment
Question by:FinghtingMiao
  • 6
8 Comments
 

Author Comment

by:FinghtingMiao
ID: 36546370
I already figure out the issue 2 just use reset to 0 for each record.
But is anyone can help me on issue1?
Thank you a lot.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 36546591
The subreport has to be in a section before the main report usage.

Where is the main report formula?

You may have to add extra sections
Right click the detail section in the left margin
Click INSERT SECTION BELOW
There is no a details A and B
Details A can have the subreport while details B can have the main report formula.

All main report formulas are evaluated before a subreport is evaluated in the section.

mlmcc
0
 

Author Comment

by:FinghtingMiao
ID: 36550206
mlmcc:
The solotion u provided works! But the @reset does not work any more.
@reset
whileprintingrecords;
NumberVar Prior_Lease_Year_Sales:=0;

I put  it in the main report, and no matter where I put it, the Prior_Lease_Year_Sales sitll display last record(sale id)'s value if the subreport return no data. But what I am lookin for is: If subreport bring no data for this record, the Prior_Lease_Year_Sales should display 0.

Thanks again!
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:FinghtingMiao
ID: 36550230
SOrry, I got the answer! I just miss-spell the variable name.

Thank you!
0
 

Author Comment

by:FinghtingMiao
ID: 36550725
I've requested that this question be closed as follows:

Accepted answer: 0 points for FinghtingMiao's comment http:/Q_27311024.html#36550230
Assisted answer: 500 points for mlmcc's comment http:/Q_27311024.html#36546591

for the following reason:

thank you. It is a good tip I should keep in mind if use shared variable in crystal report
0
 

Author Comment

by:FinghtingMiao
ID: 36550726
Miss type
0
 

Author Closing Comment

by:FinghtingMiao
ID: 36550730
thank you. It is a good tip I should keep in mind if use shared variable in crystal report
0
 
LVL 34

Expert Comment

by:James0628
ID: 36553754
 > I just miss-spell the variable name.

 You have to be very careful about that.  CR doesn't try to do any cross-checking or anything like that.  If you mis-type a variable name, you just create a new variable.  I will often copy variable declarations from one formula and paste them into other formulas, to make sure I get the names correct (and just to save some typing :-).

 You also need to be careful about the variable types - Local, Global and Shared.  They're all separate.  If you declare a Shared variable in one formula and a Local variable with the same name in another formula, those are two separate variables.  You have to make sure that the names and types are consistent.

 James
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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