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!

shared string array variable

Status
Not open for further replies.

kims212

Programmer
Dec 17, 2007
103
CA
crystal report xi, windows 7

I am creating a sub-report which I will eventually link to the main report when it's working.

I created three array variables, one string, two number.

My member contact records have an industry code so I sort and group by industry code - which I've actually translated to industry name - and using running totals, count the # of records - members - in an industry, reset on a change of group (industry), and the count of groups, not reset.

what I'm trying to do is to calculate the page number in the membership directory, based on the number of member contacts in each industry.
I started with using global array variables and all worked well, but of course I had to switch to shared variables so I changed the scope of the global array variables to shared - and then the trouble began.

Each time I updated the shared array element with a value - industry name, # members in an industry or industry page # - the preceding value was cleared out, i.e. when I updated the values in the 2nd element of the arrays, the values in the first element of the array were zero for number arrays and "" for the string array; updating the values to the fifth element, the first four were cleared - but the first three would have been cleared when the formula was processed for those elements. the global variables had worked fine.

then I changed the scope of shared array variables back to global and created corresponding new shared array variables, no luck, same problem with the shared arrays.

then I created two shared string variables in which I concatenated i) the industry name or ii) totext(members in industry) at the point that I updated the arrays, assuming that I'd get a string of i) industry names and ii) number of members in the industry; but that gets cleared out as well and the string variables contain only the values of the last element in the group. I printed the strings in the group footer and each time, it held only the group industry name an number of members of the last array element.

of course, this worked fine for the global string variables.

I have a formula in the report footer that reports the values in global and shared arrays. the global are all correct, but the shared contains a value in only the last element.

then, I created a formula to initialize the shared string array and string variables with dummy data and put it in the report header; I had no formulae anywhere in the report that updated the shared arrays and strings so the shared array and string calculations and updates weren't done. I printed the string variables in the group footer; the industry name string was fine and never changed, but the # of members string didn't print anything.

the formula in the report footer, showing the industry name, # of members, and the page number for each shared array element, the the first six elements were as I had entered them in the initialization formula - the # of members for each industry were also as I had initialized them even though the string never reported in the group footers - and the remining ones had blank industry names and 0 members in industry; the page # perpetuated based on no members in the industry and was the same for the all of the remaining elements. that was correct based on the data.

so, finally, in the formula that I put in the in the report footer, I copied the elements from the global arrays to the shared arrays which did actually work, but seems a very inelegant solution; I had hoped to not have to use the global array variables at all and just have the shared array variables.

it seems the array isn't the problem, as the string variables are also cleared. in each formula where I use the shared array variables I declare shared stringvar array industry_names and shared numbervar array members_in_industry and the string variables, which I thought was what I had to do and is what I do with the global array variables; am I clearing out the arrays when I do that? not from what I understand and the global arrays don't do that.

I know that it sounds like I've redimmed the arrays and initialized the strings, but I really haven't, honestly.

I have blethered on at great length, but it was to give you as much information as possible so you wouldn't need to ask a lot of questions.
I'm really missing something about shared variables; I've used shared variables before, but not shared arrays; of course the string variable doesn't seem to be working either.

of course I'll be happy to send whatever will help but didn't want to send something not useful.

By the way, is there anyway to interupt processing in a formula to see what's happening like you can in Visual Basic, other than by setting up a divide by zero; CR doesn't seem to have much in the way of debugging tools.

well, thanks for getting through all of that; it would be so wonderful if someone can help me out, the directory is coming out n a couple of weeks.

thanks
Kim




 
Please--instead of describing everything, just show the actual formulas you are using (including any nested formulas), say what section they are in, and identify your group structure. It sounds like you are aiming for an index or table of contents of sorts at the end of the report.

Also, explain why are you are using a subreport in the first place, and where it is located in the main report. Also not sure why are you using running totals, rather than simple summaries.

-LB
 
Hi lbass

thanks for responding so quickly.

here are the formulae that update the shared arrays:

this updates the number of members in a company to the shared number array
this is in the group footer

EvaluateAfter ({@define_industry_and_count_shared});

shared numbervar array cos_in_industry_shared;
shared stringvar array industry_name_shared;

shared stringvar cos_in_industry_string;
shared stringvar industry_name_string;

cos_in_industry_shared[{#group_position_in_array}] :={#total_cos_in_industry};
cos_in_industry_shared[{#group_position_in_array}];


this updates the industry name to the shared string array:
also in the group footer

EvaluateAfter ({@define_industry_and_count_shared});

shared stringvar array industry_name_shared;
shared numbervar array cos_in_industry_shared;
shared stringvar industry_name_string;
shared stringvar cos_in_industry_string;

industry_name_shared[{#group_position_in_array}]:={@group1_name};
industry_name_string:= industry_name_string + space(5) + industry_name_shared[{#group_position_in_array}];
industry_name_shared[{#group_position_in_array}];


this calculates and updates the page number to the shared number array:
this is in the report footer

WhilePrintingRecords;

shared stringvar array industry_name_shared;
shared numbervar array cos_in_industry_shared;
shared numbervar array industry_page_no_shared;

local stringvar toc_listing_shared;
local numbervar i;
local numbervar y;
local numbervar page;
local numbervar element;
local numbervar no_rem_on_page;
local numbervar left_over_after_full_page;
local stringvar part1;
local stringvar part2;
local stringvar part3;
local stringvar part4;


element:=0;
page:=3;

do
( element:=element + 1;
industry_page_no_shared[element]:=page;
y:=cos_in_industry_shared[element];
page:=page + (y\6);
left_over_after_full_page:=y mod 6;
no_rem_on_page:=no_rem_on_page - (y mod 6);

if left_over_after_full_page > 0 then
if cos_in_industry_shared[element+1] > no_rem_on_page
then (page:=page + 1;
no_rem_on_page:=6;)
)
while element <= {#group_position_in_array};

toc_listing_shared:='';
i:=0;
part1:='';
part2:='';
part3:='';
part4:='';

do
( i:=i+1;

part1:='name:' + space(5) + industry_name_shared + space(10)+ chr(10);
part2:='#companies:'+ space(5) + totext(cos_in_industry_shared) + space(10)+ chr(10);
part3:='page #:' + space(5) + totext(industry_page_no_shared) + space(10)+ chr(10);
part4:='# on last page:' + space(5) + totext(cos_in_industry_shared mod 6);

toc_listing_shared := toc_listing_shared + part1 + part2 + part3 + part4 + chr(10) + 'position in array:' + space(5) + totext({#group_position_in_array})+ chr(10) + chr(10);
)
while i<={#group_position_in_array};

toc_listing_shared;

I think that that's all of the formulae that matter.
the formulae for updating the global arrays and calculating the global page number arrays are exactly the same, using different variable names and are in the same sections as the shared variable formulae.

yes, I'm trying to generate a table of contents for our membership directory, but not at the end of the report; the toc is to go at the beginning of the report which is why I'm using a sub-report to determine the page numbers to pass to the main report ; the sub-report is to be located at the beginning of the report before the directory listings begin.

each member record has an industry code; I sort and group by the industry code. I suppress the details and group heading sections; the update formulae are in the group footer and the page number calculation is in the report footer after all of the arrays have been updated to calculate the page number based on the values in the arrays.

running totals? I'm not sure my reasoning, I started this quite some time ago, but, they work well.

thanks again for your quick reply.

kim

I have to go home now, it's past 6:30 our time, but I'll check in tomorrow.





 
Hi lbass

here's a funny thing

in each of the following two formulae which I included above, I commented out the line: EvaluateAfter ({@define_industry_and_count_shared}); and it worked perfectly.

I had that same EvaluateAfter line in the update member count and industry name to the global arrays and that worked fine.

it seems that it treats the EvaluateAfter differently for shared variables as opposed to global variables. I don't know that this can be handled any other way.

this I did not know.

this updates the number of members in a company to the shared number array
this is in the group footer

EvaluateAfter ({@define_industry_and_count_shared});

shared numbervar array cos_in_industry_shared;
shared stringvar array industry_name_shared;

shared stringvar cos_in_industry_string;
shared stringvar industry_name_string;

cos_in_industry_shared[{#group_position_in_array}] :={#total_cos_in_industry};
cos_in_industry_shared[{#group_position_in_array}];


this updates the industry name to the shared string array:
also in the group footer

EvaluateAfter ({@define_industry_and_count_shared});

shared stringvar array industry_name_shared;
shared numbervar array cos_in_industry_shared;
shared stringvar industry_name_string;
shared stringvar cos_in_industry_string;

industry_name_shared[{#group_position_in_array}]:={@group1_name};
industry_name_string:= industry_name_string + space(5) + industry_name_shared[{#group_position_in_array}];
industry_name_shared[{#group_position_in_array}];

much ado about nothing!

kim
 
hi lbass

I've been searching and googling and can't find anything that confirms that the evaluateafter behaves differently for a global array variable and a shared array variable, or that it would cause the formula to be executed every time in the shared array update and only once for the global array variable even though the formulae are the same

is this the way it works?

is there a reason that it works differently for a global vs a shared array variable?

thx
kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top