Click to See Complete Forum and Search --> : Need to Declare a Global Variable WhileReadingRecords, to be used in Grouping/Sorting


Wenin
March 15th, 2008, 10:31 AM
I don't know if this is possible within Crystal, but this is what I'm needing to do.

I want to obtain the data from the first record (or any record would do actually), to set a global variable.

StringVar FirstPlan;

if instr({SampleData.UC_Information_Unit_Container_ID_LKUP},':') > 0 then
FirstPlan = Left({SampleData.UC_Information_Unit_Container_ID_LKUP},
instr({SampleData.UC_Information_Unit_Container_ID_LKUP},':') - 1)
else
FirstPlan = {SampleData.UC_Information_Unit_Container_ID_LKUP};

I place the above formula field in the Report Header, suppressed

I want to sort by the results from this formula, and the global variable would be used in this formula.

if {SampleData.UC_Information_UC_Information_Type_ID_LKUP} = 'Definitions' then
FirstPlan + '03' + {SampleData.UC_Information_UC_Information_Type_ID_LKUP}
else
{SampleData.UC_Information_Unit_Container_ID_LKUP} +
if Length(ToText({SampleData.UC_Information_Sequence},0)) = 1 then
'0' + ToText({SampleData.UC_Information_Sequence},0)
else
ToText({SampleData.UC_Information_Sequence},0) +
{SampleData.UC_Information_UC_Information_Type_ID_LKUP}

Problem - FirstPlan isn't recognized as a declared variable.

Crystal Report identifies "FirstPlan" and states
"A number, currency amount, boolean, date, time, date-time, or string is expected here."

Wenin
March 15th, 2008, 11:54 AM
Stepping away from the issue made me realize the solution. =)

Since I can obtain the FirstPlan name from any record as I devised (which I hadn't realized until I was writing the original post), then I can combine both formulas and run it as I've done all my other formula driven group/sorting I've ever done. =)


Is anyone able to explain why the previous setup wouldn't work?

Wenin
March 15th, 2008, 12:14 PM
I'm still running into a problem, for some reason the variable isn't being given a value......