• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 510
  • Last Modified:

Shared Array issue from a subreport

I am having a problem, everytime I reference my shared stringvar array x in a sub report. My main report only displays the last value on a x[1], or only pulls a value of one from a ubound(x).

Help!

Code Example

Shared StringVar Array TR;
TR:= MakeArray (file.name);

TR[1]

The above code is placed in the detail line to it displays all records in the array. Whenever I ubound the array in the subreport it still only displays a 1 instead of the total count of the array. Also whenever I try to pull any value from the array in the sub report I only ever retrieve the first value.

Thanks!
0
PPhippsJR
Asked:
PPhippsJR
  • 2
1 Solution
 
James0628Commented:
All you're doing in that code is putting file.name in the first element of the array, so if that's all that you're doing, there will only be one element in the array.  You'll just keep putting different values in file.name (Is that a field?) in that first element.

 You need to use something like:

TR [ x ] := file.name;

 where x is something that is incremented for each new value.

 If you want to store a new value for each record, you can use RecordNumber:

TR [ RecordNumber ] := file.name;

 If the situation is somehow more complicated, you may need to use a shared number variable that you increment manually as appropriate.


 The other thing you'll need to do is set the dimensions of the array.  If you know how many elements there will be, you can use Redim in the first formula that creates the array (which should be in the report header of the main report) and set the maximum size there.  Or, you can use Redim to set an initial size, and then check it as you add new elements and use Redim Preserve (to keep the current contents) as necessary.  Something like:

Shared StringVar Array TR;
if RecordNumber > UBound (TR) then
(
// Resize TR, and add 100 extra elements
  Redim Preserve TR [ RecordNumber + 100 ];
// You can't end an if-then with a Redim
 ""
);

TR [ RecordNumber ] := file.name


 You can change the Redim Preserve TR [ RecordNumber + 100 ] as you see fit.  I like to add some extra elements when resizing an array, so I'm not resizing it with each new value.  How many extra you add is up to you.  You might want to just add 10 or 20 at a time.  It depends a lot on your data.

 James
0
 
James0628Commented:
I may be biased :-), but I think I hit the nail(s) on the head.  It might have taken some more work to get his formulas and variables doing whatever he really needed to do, but I think I explained the problems he described and some ways to correct them.

 James
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now