Print Page | Close Window

Sharing Conditional Variables

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=20064
Printed Date: 08 May 2024 at 12:10pm


Topic: Sharing Conditional Variables
Posted By: bpmcnary
Subject: Sharing Conditional Variables
Date Posted: 28 Sep 2013 at 10:20am
Hi,
 
I think my question is in regards to global variables, but I may be wrong.This is somewhat complex to explain!
 
I have a set of financial statements which uses the parameter "Fund Family". In these families, two entities can exist. Let's just call them A and B.
 
When I run the financials for a fund family, two sets of financial statements come out -- one for Fund A and one for Fund B. This is exactly what I wanted. The issue comes in when I attempt to share data to a supplementary report below the financials.
 
Because there are two sets of financials coming out, when I attempt to share my total assets to the supplemental, I get the wrong value. I'm trying to share the asset number for Fund A to specific place in the report, and then share the number for Fund B. Is there any easy way of setting these criteria?
 
If I could write the formula it would look somewhat like the below. Don't judge me, it's definitely incorrect, but that expresses it well.
 
IF Fund A then Shared Value FundATotalAssets
   ELSE Shared Value FundBTotalAssets
 
Any thoughts on this? Any help would be greatly appreciated!
Brandon
 



Replies:
Posted By: lockwelle
Date Posted: 30 Sep 2013 at 5:07am
is the supplemental report a subreport? if so, you want shared variables, not global.

I am not sure how you determine the Fund A for the formula, but it might need to be a variable as well.

Shared/global variables are pretty easy to use, they are used in formulas and tend to come in sets of 3:
reset, increment, display.

I think for your report though, you only really need the increment (or set in this case)

shared stringvar x := {table.field};
"" //will hide the setting of the variable.

to use the variable, all you need at the top of your of your formula is:
shared stringvar x;

now you can use x as if it was part of the formula/report and the value is whatever was set prior.

as a last note, := is the assignment operator for variables, and a global variable can be seen anywhere in a report, while a shared variable can cross the boundary into another report.

HTH


Posted By: bpmcnary
Date Posted: 30 Sep 2013 at 9:14am
Hi Lockwell,
 
Thanks for the response. I am currently using shared variables, the problem is is that it shares the last total asset number (there would be two in a fund family) in the report.
 
So if Fund A was 1 dollar and Fund B was 2 dollars, it would share the 2 dollars down. Fund A and Fund B run together, so when you run the reports you get two sets of financial statements. What i'm looking to do is define a shared variable for just the Fund A number or Fund B number.
Thanks,
Brandon


Posted By: lockwelle
Date Posted: 30 Sep 2013 at 9:21am
if both of the sections of report that access the shared variable are using the same shared variable, then only 1 result will prevail.

it's like have a joint checking account. 2 people write checks, which is the last check written/processed. So in this case, FundA would need its own variable as would FundB...where it gets complex is if there are x Funds being tracked.

If that were the case, I would use a shared array, and would have a 'naming' convention (or another array) to match the funds to their value (it can even be the fund name + the value...say FundA|xyz. It would take more work, but I think that something like is what you are after...unless there are always only x funds, then you could just create the variables.

HTH


Posted By: bpmcnary
Date Posted: 30 Sep 2013 at 2:09pm
Hi Lockwelle,
 
This is exactly what I needed. In terms of syntax, this is what I wrote --
 

WhilePrintingRecords;

Shared NumberVar Array Assets;

IF {Main.Main Fund or Parallel Fund} = "Main Fund"

THEN Assets[1]:=

{@ Total Assets}

ELSE IF {Main.Main Fund or Parallel Fund} = "Paralell Fund"

THEN Assets[2]:=

{@Total Assets}

 

I'm getting an error saying that "a variable cannot be redeclared as a different type". This is my first time writing an array formula, so any help with this would be awesome. Also, in the case above, how would I referencing it in the below subreport for Fund A?

 
 
Would it be... Shared NumberVar Asset[1];  ?
Thanks!
Brandon


Posted By: lockwelle
Date Posted: 01 Oct 2013 at 4:57am
you would reference it the same. In the subreport you would start the formula as:
shared numbervar array Assets;


Then in the formula itself it would be Assets[1]

The error seems to imply that the value being returned by @Total Assets maybe a string one time and number another.   If it always returns a number, the only other thought is do you 'declare' the array to have 2 members?

I haven't used arrays too often as they are kind of limited in CR, so I might be missing something...

HTH



Print Page | Close Window