Link to home
Start Free TrialLog in
Avatar of FinghtingMiao
FinghtingMiaoFlag for United States of America

asked on

Crystal Report Shared Variable bring 0s

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!
Avatar of FinghtingMiao
FinghtingMiao
Flag of United States of America image

ASKER

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.
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
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!
SOrry, I got the answer! I just miss-spell the variable name.

Thank you!
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
Miss type
thank you. It is a good tip I should keep in mind if use shared variable in crystal report
Avatar of James0628
James0628

 > 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