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!

create a dynamic array

Status
Not open for further replies.

huytonscouser

Programmer
Oct 14, 2011
88
US
i want to create an array of names, but i do not know how many elements i need in the array, until the data is displayed.

how do i create a dynamic array of the names. the number of names will be between 100 and 200. where do i place the create array formula. thanks in advance.
 
Are you collecting the names from the detail section of the report? Then you would create a formula like this for the detail section:

whileprintingrecords;
stringvar array x;
numbervar i := i + 1;
if not({table.name} in x) then (
redim preserve x;
x := {table.name}
);

Then in the report footer you can use a formula like this to display the array:

whileprintingrecords;
stringvar array x;
stringvar y;
numbervar i;
numbervar j := ubound(x);
for i := 1 to j do(
if x <> "" then
y := y + x+", "
);
left(y, len(y)-2);

-LB
 
Thank you LB,
Your array formulas do actually work, thank you. I did change the datatype to numbervar to hold "array allocated gb".
then i am able to see the differences when i place the 2nd formula in report footer.

The reason i was asking for arrays, is that i want to calculate the daily difference for the "array allocated gb" the way i am currently doing this is :-

numberVar difference;
numbervar Totaldifference;
numbervar previousvalue;
if onfirstrecord then
(
difference :=0;
Totaldifference :=0;
previousvalue :=0;
)

else
if {SRMARRAY.ARRAYALIAS} = previous({SRMARRAY.ARRAYALIAS})
then
(
previousvalue := previous({SRMARRAYMETRICS.ARRAYALLOCTOTAL})/1024/1024;
difference := {SRMARRAYMETRICS.ARRAYALLOCTOTAL}/1024/1024 - previousvalue;
totaldifference := totaldifference + difference;
difference;
)
else 0


But because i use PREVIOUS in the formula, i am unable to summarize this formula, so am wanting a way to do this.

Currently i cannot attach a screenshot as i am behind a firewall, sorry. So maybe this will help you, 6 coluns in details, and then 2 rows in report footer :-

10/19/2011
ARRAYALIAS Array Allocated GB Daily Difference Growth DATEKEY Array for alocated
PHX_T123_3520 117,489.05 0.00 0.00 20,111,014.00 117,489.05
PHX_T123_3520 117,489.05 0.00 0.00 20,111,015.00 0.00
PHX_T123_3520 117,489.05 0.00 0.00 20,111,017.00 0.00
PHX_T123_3520 117,523.09 34.03 0.00 20,111,018.00 117,523.09
PHX_T123_3520 117,523.09 0.00 34.03 20,111,019.00 0.00
PHX_T3_3747 158,056.93 0.00 0.00 20,111,014.00 158,056.93
PHX_T3_3747 158,056.93 0.00 0.00 20,111,015.00 0.00
PHX_T3_3747 158,056.93 0.00 0.00 20,111,017.00 0.00
PHX_T3_3747 158,124.93 68.00 0.00 20,111,018.00 158,124.93
PHX_T3_3747 159,148.93 1,024.00 1,092.00 20,111,019.00 159,148.93
Total growth for all clusters 1,126.03
Daily values for array allocated from array 117,489.05, 117,523.09, 158,056.93, 158,124.93, 159,148.93


 
Which column is your formula returning? Is it working the way you expect? I can't tell what it is you want to sum or where you think the problem is. Using your sample, what is the result you are trying to achieve?

-LB
 
PS. And I'm not sure what the array has to do with it or why you think you need one.

-LB
 
lb, the report has 2 columns that i need to summarize, and yes both appear in the report correctly. But i cannot see either of them if i want to do any summary. i.e. total the growth column.

the 2 formulas/columns on the report are "daily difference" the formula is in the previous message, and uses PREVIOUS to calculate the difference from yesterday and today. The other formula "Growth" calculates the accumulated growth during the period. It uses NEXT. Here is the formula :-

numbervar firstvalue;
numbervar lastvalue;
stringvar arrayname;
numbervar resetfirstvalue;
numbervar percentgrowth;
if onfirstrecord then
(firstvalue :={SRMARRAYMETRICS.ARRAYALLOCTOTAL}/1024/1024;
arrayname := {SRMARRAY.ARRAYALIAS};
0;)
else if onlastrecord then lastvalue := ({SRMARRAYMETRICS.ARRAYALLOCTOTAL})/1024/1024 - firstvalue
else if arrayname <> next({SRMARRAY.ARRAYALIAS})
then
(
arrayname := next({SRMARRAY.ARRAYALIAS}) ;
resetfirstvalue := firstvalue;
firstvalue :=next({SRMARRAYMETRICS.ARRAYALLOCTOTAL})/1024/1024;
lastvalue := ({SRMARRAYMETRICS.ARRAYALLOCTOTAL})/1024/1024 - resetfirstvalue;
)

else if not onlastrecord and arrayname = next({SRMARRAY.ARRAYALIAS})
then
(
arrayname := arrayname;
0;


I am ultimately trying to produce a report, that has a group header which shows :-
ArrayName / Growth

PHX_T123_3520 34.03
PHX_T3_3747 1,092.00

Total growth for all 1126.03


The details section would be hidden.

I cannot see the daily difference or growth formula when i try and make a summary. That is why i was wondering if i could capture all the data i need in arrays, and then do the calculations like :-

difference := array x[current entry) - array x [previous entry]

i hope this helps you understand a little better what i am trying to achieve. I really appreciate your help.
 
You can do this more simply without arrays.

Insert a group on the array name, and aim to use the group footer for your results with group header and details suppressed.

Add a formula like this to the detail section:

//{@dailydifftot}:
whileprintingrecords;
numbervar diff;
numbervar totdiff;
if not onfirstrecord and
{SRMARRAY.ARRAYALIAS} = previous({SRMARRAY.ARRAYALIAS}) then
diff := {SRMARRAYMETRICS.ARRAYALLOCTOTAL}/1024/1024 -
previous({SRMARRAYMETRICS.ARRAYALLOCTOTAL})/1024/1024;
totdiff := totaldiff + diff;
if not onlastrecord and
{SRMARRAY.ARRAYALIAS} = next({SRMARRAY.ARRAYALIAS}) then


//{@reset} for the group header:
whileprintingrecords;
numbervar diff := 0;
numbervar totdiff := 0;

//{@displaytotdiff} for the group footer:
whileprintingrecords;
numbervar totdiff;

I think you could simplify the growth formula, too. If values can only increase and not go up and down, then you could just compare the maximum for the arrayname group with the minimum to calculate the growth. If you need to use variables to compare the first and last values, then you should add "whileprintingrecords" to your formulas.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top