Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sharing variables and resetting value

Status
Not open for further replies.

Keoki

Programmer
Feb 22, 2000
22
US

Forums



Message Thread:


--------------------------------------------------------------------------------


I am using a shared variable to pass the results of a formula from a subreport to a main report. If the value of the results is other than zero, than the receiving formula/variable in the main report works fine. If the results equal zero, the subreport calculates the passing formula/variable just fine, but the receiving formula/variable is holding on to the results of the previous calculation that had a result other than zero.

I have tried resetting the variable value to zero at the beginning of the passing formula/variable, but it didn't make any difference. The formula I have used for the passing formula/variable is:

CurrencyVar PeriodDifference := 0;

WhilePrintingRecords;
Shared CurrencyVar PeriodDifference := Sum ({JEDetailSR_ttx.Debit}, {@GLAccountNumber}) - Sum ({JEDetailSR_ttx.Credit}, {@GLAccountNumber});

The receiving formula/variable is:

WhilePrintingRecords;
Shared CurrencyVar PeriodDifference;

Thanks,

Keoki



 
You must use 3 formulas to achieve your goal: one formula for initialization, another formula for evaluation, and a third formula for display.
You have no problem with the display formula:

WhilePrintingRecords;
Shared CurrencyVar PeriodDifference;

The problem is with the formula that you used for both initialization and evaluation stages.
The initialization formula should be displayed in a section prior to the section containing the evaluation formula. Write the following code for the initialization
formula
:

WhilePrintingRecords;
Shared CurrencyVar PeriodDifference := 0;

The evaluation formula is the same formula that you write, but without the line:

CurrencyVar PeriodDifference := 0;

Note: In the above line of code, the variable PeriodDifference of type CurrencyVar is not Shared. The default type for the scope is Local. SCR is not intelligent enough to know that since such variable is declared as Shared in one formula, then it has such scope in all formulas in both the subreport and the main report. In any formula (in the main report or any subreport), the variable must have the following type:
Shared CurrencyVar

The evaluation formula (should be located in a section after the section containing the evaluation formula) would be as follows:

WhilePrintingRecords;
Shared CurrencyVar PeriodDifference := Sum ({JEDetailSR_ttx.Debit}, {@GLAccountNumber}) - Sum({JEDetailSR_ttx.Credit}, {@GLAccountNumber});

I hope that I understood your question and were able to represent an answer for it.
 
Thank you for replying to my question. Believe it or not, I had figured out how to do it. My solution is pretty similar to yours.

First, I created a formula to calculate the difference between the credits and debits, such as:

CurrencyVar TempResult := Sum ({@Debit}, {@GLAccountNumber}) - Sum ({@Credit}, {@GLAccountNumber});

In a second formula, I tested for the result of TempResult and based on the result, then initialized PeriodDifference:

If IsNull({@PeriodDifference_Temporary}) or ToText({@PeriodDifference_Temporary}) = "" Then
(WhilePrintingRecords;
Shared CurrencyVar PeriodDifference := 0;)
Else
(WhilePrintingRecords;
Shared CurrencyVar PeriodDifference := {@PeriodDifference_Temporary};)

It had finally dawned on me that since in some cases there were no debits and credits for a particular subreport, so the shared formula wasn't being initialized properly.

I do appreciate the quick response. I sent this same question to both the Seagate Crystal Report tech support and
the forum site last Friday, and still haven't heard on either.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top