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

do shared variables move on a one way road? 1

Status
Not open for further replies.

cmpgeek

Technical User
Feb 11, 2003
282
US
i have been using regular variables for a couple months now with no problems at all, but for the report i am writing now, i need a shared variable - one that begins in the subreport and travels to the main report...

the impression i get from reading the crystal guide is that shared variables start in the main report and feed into the subreport... (it tells you to use this code in the main report:
shared numbervar x := 1000;
and then
shared numbervar x;
in the subreport...

maybe i am reading it wrong, but that makes me think that it is traveling from the main to the subreport...

is there no way to have a variable travel FROM the subreport to the main report?

thanks for your time and any suggestions you may have...

 
Shared variables work in both "directions".

In the main report, just declare and use the shared variable (set within a subreport) in a formula placed in a section BELOW the section where the subreport is (because the subreport is the last thing to be evaluated in the section).

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
ok, i understand placing it somewhere after the subreport (although i probably would not have thought of that without your telling me thanks)...

but now what i am wondering is if i use

shared numbervar costtotal := {@mytotalcostfield}

in the subreport... and then type

shared numbervar costtotal; in the main report i get an error saying unknown field... how do i get the main report to accept that field, or will it accept it as soon as i hit preview?
 
Show your full formula from the main report.

Soemthing else is triggering the error message.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
well i wrote the formula just as i wrote it above... which was right out of the crystal guide book... in the subreport i wrote

shared numbervar costchargetotal := {@pcpcfooter)

in the main report:

shared numbervar casechargetotal;

i dont mean to seem dumb, but when i dont know for sure - i do it exactly as it shows me...

...feelin the hammer coming on... [hammer]

i am heading out for the long weekend; but thank you for all your help so far Ido...

for all you Americans out there - have a great 4th of July... [americanflag]

everyone else have a great weekend as well! [smile]
 
Your variables need to be named the same in both the sub and main reports.

Mike
 
As Mike pointed out, you have 2 different variables, try:

subreport i wrote:
shared numbervar costchargetotal := {@pcpcfooter)

in the main report:
shared numbervar costchargetotal

Think of them as global variables, once they are declared, they are available to any subreports or main reports throughout the execution of the report and it's subreports.

Keep in mind that the subreport must be in a section before the main report displays the shared variable, or if you're pawssing a shared variable to a subreport, it must be set prior to the subreport.

-k
 
cmpgeek,

The formula in the main report :

shared numbervar casechargetotal;

will never throw up an error because this is the syntax to declare a variable.

I think it's more likely that the formula :

shared numbervar costchargetotal := {@pcpcfooter)

in the sub-report is the problem.



Reebo
Scotland (Sunny with a Smile)
 
cmpgeek,

The formula in the main report :

shared numbervar casechargetotal;

will never throw up an error because this is the syntax to declare a variable.

I think it's more likely that the formula :

shared numbervar costchargetotal := {@pcpcfooter)

in the sub-report is the problem. Post your formula ....



Reebo
Scotland (Sunny with a Smile)
 
As the guys have pointed out earlier, you do need to keep the variable name consistent in order to display and/or manipulate the values. However, different variable names will not return an error like you're getting. They will just be treated as two completely different variables.

I would suggest to you that you check the syntax of your fieldnames. Check entries like this: {@pcpcfooter) that should really look like this {@pcpcfooter}. Your error is stemming from the fact that you are probably typing your fieldnames in rather than selecting them from your fieldexplorer and in doing so have made a typo. Ensure that your fieldnames match those in your dataexplorer.

Naith
 
fortunately the typos i made were only here... i am not sure what was causing the glitch with it on Thursday. Wheni got here this morning and previewed i was getting values for the variables in the main report that were the same as the ones in the subreport... i did however have to make a second detail section as Ido suggested.

i have since gotten totals and averages of each... and it seems to be working great...

the only extra work involved is exporting it to Excel so i can make graphs based on the variables... is there any chance CR 9 solves the issue of not being able to graph variables at all?

thanks again for all your suggestions... i would not do nearly as well with CR if not for this site and its awesome people!!!
 
Actually, there's the following "dirty trick" that may let you do the chart within Crystal.

Instead of attempting to create the Chart in the main report, create formulas in the main report that hold the values of the varibales. Then, pass these formulas as links to a subreport. Finally, in the subreport, create your chart. Sounds strange at first glimpse, but if you think about it, subreports treat the values of links as raw data - the subreport doesn't know these values are "special" from the point of view of the main report... :eek:)

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top