Shared Array issue from a subreport

Posted on 2010-01-06
Last Modified: 2012-06-21
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).


Code Example

Shared StringVar Array TR;
TR:= MakeArray (;


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.

Question by:PPhippsJR
    LVL 34

    Accepted Solution

    All you're doing in that code is putting 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 (Is that a field?) in that first element.

     You need to use something like:

    TR [ x ] :=;

     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 ] :=;

     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 ] :=

     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.

    LVL 34

    Expert Comment

    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.


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
    I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now