PDA

Click to See Complete Forum and Search --> : Problem with shared variables


Magoo5289
May 13th, 2004, 11:08 AM
I'm trrying to take the total from one subreport and make it divide by the total of another subreport to come out with a certain percentage which is shown in the second subreport. I have declared the shared variable in the main repot and have managed to assign the correct value within the first subreport. However, that value does not seem to be coming out of that subreport as when I go into the second subreport and attempt the division, I get a divide by zero error, which is what the value is set to in the main report. Any suggestions on how I can correct this?

techgnome
May 13th, 2004, 12:11 PM
How do you have the variable declared?

TG

Magoo5289
May 13th, 2004, 01:53 PM
Well in the main report it is declared as

shared numbervar nfg :=0;



in the subreport it is shared numbervar nfg := fieldname;

which correctly assigns the field value to the variable nfg.



in the second subreport it is

(count of field name)/shared numbervar nfg

which results in a divide by zero error.

which says to me that the variable is not carrying out of the subreport.

techgnome
May 13th, 2004, 02:15 PM
This is going to sound stupid, but I think what you will need to do is split the section into two sections, put one sub report in to one, and the other in the other. Because the subs are in the same section at the same level, Crystal tries to render them together. What you need to do is have the first one render first, then deal with the second. It sounds stupid and lame, but I had that very problem once before. To solve it, we put the two reports into different subsections and forced one to render first.

TG

Magoo5289
May 13th, 2004, 02:36 PM
That does seem to make a lot of sense now that i think about it. I do have them in separate detail lines however, that is what you are are suggesting, correct?

brucevde
May 13th, 2004, 04:02 PM
He is referring to Sections not Lines. If you were not aware, you can have one or more of each section type.

Right click on the section name and choose the "Insert Section Below" menu item. You will now see an "a" and "b" section, ie "Details a" and "Details b".

Crystal processes each section in turn. If you place the second sub-report in "Details b", nothing happens until the "Details a" section has completed. If sub-reports are in the same section, Crystal spawns multiple threads and processes them simultaneously.

One more thing, its not clear from your posts but did you declare the shared variabe in the second sub-report. Every formula that uses a shared variable must have the exact same declaration.

Okay, now one more thing. I seem to recall that a line which uses a shared variable must end with a semi-colon;.

Magoo5289
May 19th, 2004, 12:28 PM
Sorry it took me so long to get back on this issue, but I have been multitasking recently.

All of the subreports in my report are in different sections and yet it still does not seem to be carrying over any of the relevant data. Ie one report in detail lines a, another report in detail line b... semicolons are after every line of code. Any ideas?