Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Crystal Report Shared Variable bring 0s

Posted on 2011-09-15
8
321 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Join issues with Crystal Report 10 74
Crystal Reports 9 and Subreports 3 78
Crystal Reports Date Calculation 10 42
Crystal Reports Version 7 4 33
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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