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

Creating Array

Status
Not open for further replies.

dpchuck

Programmer
Jun 24, 2004
1
0
0
US
I have run into problems trying to create my first Crystal array in version 8.5. Can you please tell me what I am doing wrong from looking at the problems commented in italics within the formula codes. Thanks for any help you can give.

//INITARRAY is a formula in the Report Header //
// deptarray is the array for all the department names
// officearray are all the corresponding department numbers
// costdept is the accumulating totals for each department

// This checks out ok until the program executes and then //
// Get Error “A subscript must be between 1 and the size of the array.” //
// pointing at the very beginning just before the first shared //

shared stringvar array deptarray;
shared stringvar array office2array;
shared numbervar array costdept;

deptarray[1] := "";
office2array[1] := "";
costdept[1] := 0;



//DEPTTOTALARRAYS is formula to be put into detail //
numbervar acntr := 0;
numbervar max := UBound(deptarray);
// Get Error “The ) is missing” pointing after the ( and before deptarray in Ubound //

while acntr <= max Do
( acntr = acntr + 1;
If {IS_HelpDesk.sDepartment} = deptarray[acntr] Then
// Get Error “A number, currency amount, Boolean, date, time, or string is expected here” pointing at beginning of deptarray[acntr]. //
costdept[acntr] = costdept[acntr] + {@TotalCosts}
Else
deptarray[acntr] = {IS_HelpDesk.sDepartment}
office2array[acntr] = {IS_HelpDesk.sOffice2}
costdept[acntr] = {@TotalCosts}
);
 
There are lots of problems with the above formulas.

I would suggest that you explain what you are trying to do rather than what has not worked.

Refer to faq149-3762 for raising a question.

I'll try to explain what the error messages are referring to.
// This checks out ok until the program executes and then //
// Get Error “A subscript must be between 1 and the size of the array.” //
// pointing at the very beginning just before the first shared //


This is because you are referring to values which don't exist when you are using :
deptarray[1] := "";
office2array[1] := "";
costdept[1] := 0;

The correct syntax would be:
shared stringvar array deptarray := MakeArray("");
shared stringvar array office2array := MakeArray("");
shared numbervar array costdept := MakeArray(0);

BUT, this would only create a single value array. Another problem is you cannot add values to arrays after they have been created, only change current values. To this extent, you should create something like :

shared stringvar array deptarray := MakeArray("a","a","a","a","a","a","a","a","a","a");
shared stringvar array office2array := MakeArray("a","a","a","a","a","a","a","a","a","a");
shared numbervar array costdept := MakeArray(0,0,0,0,0,0,0,0,0,0);

This will give you the ability to change the values later.

numbervar acntr := 0;
numbervar acntr := 0;
numbervar max := UBound(deptarray);
// Get Error “The ) is missing” pointing after the ( and before deptarray in Ubound //
this message is because you haven't declared the array variable in this formula. Use : numbervar max := UBound(shared stringvar array deptarray);

while acntr <= max Do
( acntr = acntr + 1;
If {IS_HelpDesk.sDepartment} = deptarray[acntr] Then
// Get Error “A number, currency amount, Boolean, date, time, or string is expected here” pointing at beginning of deptarray[acntr]. //
this message should go now you have declared deptarray as an array variable
costdept[acntr] = costdept[acntr] + {@TotalCosts}
Else
deptarray[acntr] = {IS_HelpDesk.sDepartment}
office2array[acntr] = {IS_HelpDesk.sOffice2}
costdept[acntr] = {@TotalCosts}
);


I would still urge you to specify what you want to do and I, or someone else in the forum, will help with the best solution.






Reebo
 
As Reebo stated, if you explain your intent, you'll get better results. Your DEPTTOTALARRAYS formula is riddled with problems (e.g. not using the ":=" assignment when trying to set the values of your arrays.

And you can indeed add elements to an array at runtime. Here's an example using two formulas:
[tt]
//@Init
//This would go into the Report Header
WhilePrintingRecords;
StringVar Array Names;
"";

//@Increment
//This would typically go in the Details section
WhilePrintingRecords;
StringVar Array Names;
Redim Preserve Names[UBound(Names) + 1];
Names[UBound(Names)] := {Table.Field};
[/tt]
The first formula declares an array without dimensioning it. The second formula increases the size of the array by one in order to add a new value.

-dave

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top