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

Subreports and Shared Arrays 1

Status
Not open for further replies.

bell

Technical User
Jan 4, 2001
7
0
0
US
Hi There,

I'm trying to create a report that has one (for now) subreport that
contains a list of strings. I want to share this list into my main
report for comparison. I have been trying to use a shared stringvar array,
but I keep receiving an error that says 'a subscript must be between
1 and the size of the array'. Now my array is only 70 strings long,
when I look at it in my subreport. Here is an example of my code:

in the subreport:
whileprintingrecords;
shared numbervar counter1:={@counter};
shared stringvar array prod;
prod[counter1]:={tablename.prod_id}

in the main report:
whileprintingrecords;
shared numbervar counter1;
shared stringvar array prod;
prod[counter1];

I have placed both formulas all over the place within the main and
subreports respectively and initialized the counter and original
arrays within the subreport and still I receive the above error. Any
suggestions?
thanks
 
any chance countere1 is a zero value at that point? What does @counter do. If you hard code a number in place of @ counter does it work? ARe you sure the main report formula comes after the subreport is run?

By the way, I hope you are using V8, because you can't assign a value to an element in an array in V7. Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 
Hi,
Thanks for the quick repsonse. {@Counter} is just the a counter to count my strings (
shared numbervar counter1; counter1:=counter1+1), I've tried initializing it both with 1 and with 0, but still I've received the same error. And yes, I'm sure the main report formula comes after the subreport is run, at present, the subreport sits in details a and the main report formula in details b (I even triple checked at one point using the EvaluateAfter function). I've also tried putting one in a group one in details, and vice versus and both in groups but still no luck.
I've tried using only a select group of the original 70 to be sure it just wasn't cycling through and creating a larger array (ie over the 1000 limit) but I still receive the error. Could there be a problem with my code? Or my placement of the formulas that I mentioned earlier? Currently, the subreport holds the shared array formula within the details section and it is called in the main report also in the details section (but below).
Any suggestion would be great.
Thanks again...
ps, yes it is v8.
 
Then we need to troubleshoot.

To confirm the exact value of counter1 at the time of the error, comment out the remainder of the formula after this variable is declared. This will print the current value of the variable.

Once you know this you can also add a line that tells you how many values are in the array at that moment, using the count function.

count(prod)

Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 
Bell: You state that you've placed the subreport in the detail -a and the formula in detail - b but how have you linked the main and sub together and do you actually execute the subreport as a result of this link? As Ken suggests try rem'ing the array portion of your subreport and main formulae and just check first that you are getting a non-zero response from the subreport David C. Monks
david.monks@chase-international.com
Accredited Seagate Enterprise Partner
 
Hi,

When I comment out the remainder of the formula after counter1 in the main formula, I still receive the error, but I just noticed that the error is actually coming from the subreport formula, not the main report, so therefore I can't see the count from there.

So it looks like my real problem is that within the subreport it is cycling through the subscript too many times, when it is shared, because if I take away the 'shared' from the stringvar array, I can view everything from the subreport, but then its not in the main where I need it. Does that explain it a little better, and any suggestions?

thanks again...
 
Change the last line of the subreport to be:

Counter1

That way you can see the value that it is trying to subscript.

You can always preview just the subreport if you need to by selecting the design tab of the subreport and clicking the toolbar button for preview. If it is linked it will prompt you for a parameter. Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 
Ok, I have just done only the counter and I see a count from 1 to 70, in my subreport. If I 'share' out that only, and not the string array, I see 70, which makes sense its the last value of my counter1 and I don't see the error, until I un-rem the string array part.
So I think the subscript part is working, now I just need to see my strings. What could it be? As soon as I add in the shared stringvar array, I have a problem.
thanks
 
OK, then the problem comes when you are building the array.

Probably because you are assigning values to positions that don't exist yet in the array.

Look up the "Redim" and "Redim Preserve" topics in CR8 Help. Unfortunaately, you can't simply add an element to the array by assigning a value to the next position. Ken Hamady
Crystal Reports Training and a
Quick Reference Guide to VB/Crystal
 
Thanks for all your help, I'll try it, I may be back tomorrow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top