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

Dynamic Array not working 1

Status
Not open for further replies.

morechocolate

Technical User
Apr 5, 2001
225
US
Rosemary pointed me to the Crystal Decisions document: Advanced Reporting Techniques using Arrays, however it is not working correctly for me.

I have the following:

GH1 Tier
GH2 Loan #

Details are sorted on policy coverage type, then by policy number. I want to do the dynamic array on the property type.

Loan# Policy Type Policy# PropertyType Array
Details 12453 All 800 Office
12453 All 800 Office Office
12453 All 200 Hotel
12453 All 200 Hotel Hotel
12453 Terr 800 Office
12453 Terr 800 Office Office
12453 Terr 200 Hotel
12453 Terr 200 Hotel Hotel

Notice from the example that Office starts on the second line for the array. Office also appears above under other loan# groupings.

Here is my code:

WhilePrintingRecords;

stringVar array PropertyTypeArray;
local numberVar counter;
//stringVar strPropertyType;

//only new values are added to the array
if not({INSR_RISK;1.PR_PRTY_TYP} in PropertyTypeArray) then
(
counter := counter + 1;

//the size of an array cannot exceed 1000 CR version 8
if counter <=1000 then
(
//keep the values that are currently in the array
Redim Preserve PropertyTypeArray [counter];
PropertyTypeArray[counter] := {INSR_RISK;1.PR_PRTY_TYP};
)
);

I do not understand what is happening.
 
Well, I seemed to have solved my problem by removing the local from the variable.

Why is that? I did not have the counter variable in any other formula, at least I don't think so.

mc
 
By removing Local from the variable you made it a Global variable. Crystal automatically assigns a variable as Global if no declaration has been made.

Differences :

Local - variable can only be used within the formula
Global - variable can be used within the main report
Shared - variable can be used accross main report and sub reports.

Hope this helps. Reebo
Scotland (Going mad in the mist!)
 
OK now that I have the above working I am having displaying the correct information in GF2.

The formula is:

WhilePrintingRecords;

stringVar Array PropertyTypeArray;
stringVar strPropertyType;
numberVar counter;


For counter := 1 to UBound(PropertyTypeArray) Do
(
if PropertyTypeArray[counter] = {INSR_RISK;1.PR_PRTY_TYP} then
if (counter < UBound(PropertyTypeArray) and UBound(PropertyTypeArray) <> 1) then
strPropertyType := strPropertyType + PropertyTypeArray[counter] & &quot;, &quot;
else
strPropertyType := strPropertyType + PropertyTypeArray[counter]
);
strPropertyType

Rather than in each GF2 getting
Loan# 12453 Office
Loan# 12455 Office
Loan# 12460 Office,Hotel

I am getting
Loan# 12453 Office
Loan# 12455 Office Office
Loan# 12460 Office Office Hotel

In the GH2 the formula to reset the array is working, it is:

WhilePrintingRecords;
stringVar Array PropertyTypeArray;
stringVar ResetPropertyType;

Redim PropertyTypeArray[1];
ResetPropertyType := PropertyTypeArray[1]

Thanks

mc
 
I think that you've overcomplicated the solution, if all you want to do is show the Loan# and all of the unique property types in a comma separated fashion, try:

Group by loan#
sort by property type

Create a formula in the Group Header with:

whileprintingrecords;
stringvar Props := &quot;&quot;;

Create a formula in the details with:

whileprintingrecords;
stringvar props;
if ({table.loan#} = previous({table.loan#})
or onfirstrecord)
and instr(props, {table.propertytype}) = 0 then
props := props+{table.propertytype}+&quot;, &quot;

Then use a formula in the GF with:

whileprintingrecords;
stringvar props;
left(props,len(props)-1)

Keep in mind that CR 8.5 or below can only display 254 characters in a formula, the example data looks like this isn't a problem.

Untested as I don't have Crystal with me.

-k
 
I can't sort on property. I mentioned in previous postings what groupings and sorts I already have. Based on the nature of those groups and sorts, the Property Type field will not sort to do what you suggested.

thanks

mc
 
This works for me:

In the report header initializer:

global stringvar array test := [&quot;&quot;];
global numbervar arraycounter := 0;

In my &quot;build and display&quot; formula:

global stringvar array test;
global numbervar arraycounter;

if not({Table.string} in test) then
( arraycounter := arraycounter + 1;
Redim preserve test[arraycounter];
test[arraycounter] := {Table.string});


join(test,&quot;,&quot;)


This will fail at the join if the string gets to long, but beyond that it works.

Lisa


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top