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

Formulas and Shared Variables

Status
Not open for further replies.

swc123

MIS
Oct 28, 2002
51
0
0
US
When are Shared Variables available and how does this tie with their usage in Formulas? It appears they aren't available until AFTER the detail section line prints. Can this be changed to DURING the detail section line processes? I'll try to explain:

I have a formula in which I calculate variables to keep the logic consistent and in one place, and formulas which print these variables:

CALCFORMULA
Shared numbervar var1;
Shared numbervar var2; (var3,4,etc)
if criteria1 then
var1 := (calculation)
elseif criteria2 then
var2 := (calculation) (var3,4,etc)
elseif etc.

PRINTVAR1 FORMULA (var2,3,4,etc)
Shared numbervar var1;
var1

My detail line is:
Field field field PRINTVAR1 PRINTVAR2 etc 3 & 4

My CALCFORMULA is in the detail section as well. The printed variable values do not match the calculation of the the current detail record (ex. Table.Value1 - Table.Value2) UNTIL THE NEXT LINE.

Ex. Var1 := 22-2 s/b 20.
This does not display 20 until following line. How can I correct this?

thanks
 
I'm not sure if it will work. (I'm not at my computer with CR)
Try using the EvaluateAfter(the formula you want to caluclate first) It's in the same "family" as WhilePringingRecord

Your PRINTVAR1 FORMULA would look like this:

EvaluateAfter ({@CALCFORMULA});
Shared numbervar var1;
var1


Or try this:
Insert a second detail band. Move the fields that need the shared variable information from the CALCFORMULA into the second band. Put them immeadiatly below where they are now. Then format you DetailsA band to "underlay following
sections". This way DetailsA will have run and the variable will be available for DetailsB Mike
 
The second detail band is the recommended approach. Usually Shared variables are used in connecting with data in a subreport, but it doesn't look like you are doing that.

I suspect your formula will also work if you made all your variables Global, but you will need to use the evaluation time
WhilePrintingRecords; //in all your formulas

By default Global variables are WhileReadingRecords and Shared variables can only be WhilePrintingRecords.

Get in the habit of putting an evaluation time in your variable formulas. relying on a default can be dangerous. Editor and Publisher of Crystal Clear
 
Both ideas-EvaluateAfter and WhileReadingRecords -worked. Still working on Detail a/b to work properly.

Interestingly, I found that if I made all variables Global, I needed WhileREADINGRecords not WhilePrintingRecords in my formulas to work correctly. (we're in CR7 if it matters).

Thanks for the tips.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top