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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Shared Variables 2

Status
Not open for further replies.

MCuthill

Technical User
Joined
Jul 19, 2006
Messages
669
Location
CA
Hi Everyone,

I am wanting to use a shared variable to pass a boolean between a subreport and the main report and am having trouble getting it to work. I am using Crystal Reports 10; code as follows: (I had found a thread saying to use whileprintingrecords - but that did not change my results any)

Main Report (Group Header #1a):
Code:
whileprintingrecords;
shared BooleanVar Delinquency;

IF Delinquency = TRUE THEN "Yes" ELSE "No"

Subreport (Group Header #2d):
Code:
whileprintingrecords;
shared BooleanVar Delinquency;

IF Delinquency = FALSE THEN
(
    IF {LN.DOLDEL} > 0 THEN
    (
        Delinquency = TRUE
    )
)

I guess my question is what is wrong with my current code, or if it matters on the location of the variables on the main & subreports. I have tried commenting out the outside IF statement in the subreport formula, and again, the variable doesn't change (even within the subreport).

Thanks,

Mike

[banghead] "It Seems All My Problems Exist Between Keyboard and Chair"
 
You aren't setting the shared variable, you're just declaring it.

So here's some basic theory, you need to explicitly state a variables value, as in <variable> = <value>, it doesn't know that because you true or false or yesy or no in the code womewhere that you'd like the vairable to equal that.

Then a shared variable which is being set in qa subreport, can onl be used in the main report AFTER the subreport has fired.

It's great that you're posting your formulas, however you should take the time to state WHAT you intend the formuals to do rather than just stating they're not doing what you want them to, we don't know your requirements.

So here's an example

You have a report with a group, and within each group a subpreport, and the requirements is to add the value from a subreport to a value in the main report for each group, and then to also supply a grand total of the value.

So in the Group1 Header section and place a formula to set the value of a variable:

whilprintingrecords;
shared numbervar MyValue:=0;
shared numbervar;

Then right click the Group Header section and slect insert ssection below, and place the subreport in the Group Header 1 B section, and within the subreport place the formula:

whilprintingrecords;
shared numbervar MyValue;
MyValue:=sum({subreporttable.value})

Then back in the Main Report in the group FOOTER A place the following formula:

whilprintingrecords;
shared numbervar MyValue;
shared numbervar MyTotalValue;
MyTotalValue:=MyTotalValue+MyValue;
"Total for the subreport value and the main report value is " & MyValue + sum({MainTable.value})

So the aboive now uses the shared variable when it is available (after the subreport has fired), and in addition, we have added it to a grand total which we can use in the main report footer, as in:

whilprintingrecords;
shared numbervar MyTotalValue;
"Grand Total = " & MyTotalValue

Hopefully this helps you to understand how crystal works, and shared variables.

You need to declare variables, you need to set the value of the variables, then you need to disp;ay the variables, and the variables are available AFTER they have been set.

-k
 
Thanks SynapseVampire.

I am having a bit of trouble getting my head around where to declare, and where to change (set) the value based on criteria. I THINK that I should declare and set the value on the main report, and change it in the subreport - it just isn't working. the variable stays "FALSE" no matter what I change in the coding.

Here is my scenario:
I am developing a 'mini-CRM' system (profiling our clients) and I have a subreport showing the loans held by the profiled client. What I amtrying to do is set a flag at the top of the first page to show "Delinquency" if there is money owned (payments missed) on any of the loan accounts.

From what I read in your post, this flag at the top of the report will have to be placed AFTER the section containing the subreport (or the subreport placed above the flag). This I can work around one way or the other.

The part that is confusing me is that within the subreport the variable never changes. I have even tried changing the code in the subreport to be:
Code:
whileprintingrecords;
shared BooleanVar Delinquency;

IF Delinquency = FALSE THEN
(
    IF {LN.DOLDEL} = 0 THEN
    (
        Delinquency = TRUE
    )
)

{LN.DOLDEL} is the dollars delinquent field, the test record I am working with has 0 in this field and the variable remains as FALSE.

Any ideas would be greatly appreciated, thanks.

Mike

[banghead] "It Seems All My Problems Exist Between Keyboard and Chair"
 
You still didn't set the variable--you have to use a colon followed by the = sign.

Please explain where the {LN.DOLDEL} field is located--in the main report or in the subreport, and where the subreport is located. Is there a group on clients in the main report with the subreport linked on client and placed in a group section?

Also please explain where you want the delinquency formula to display--in the subreport or in the main report.

-LB


 
Oops. Thanks LBass.

As you may have guessed.... the colon got the variable to change in the subreport. It didn't change on the main report, however as I understood from SV, this is because it is on the main report in a grouping ABOVE where the subreport is located. Just as a test, I placed my formula field in a group footer below the subreport and the formula field showed the updated value. I think now all I need to do is re-structure the report so that a suppressed copy of the current subreport is in a group level above where management would like to see these flags displayed.

I suppose as a last question: Will the formula field on the main report work correctly so long as it is below the subreport? For example, if the subreport is in Group Header 1a, and the formula field in Group Header 1b, will this work?

Thanks,

Mike

[banghead] "It Seems All My Problems Exist Between Keyboard and Chair"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top