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!

Array generation

Status
Not open for further replies.

muhaidib

Programmer
Sep 27, 2005
82
SA
In the main report I created a formule as follows to create a shared array:

WhilePrintingRecords;
shared stringvar Array inv1Array;
inv1Array:={PAYABLETCP.IDINV};
local NumberVar howmany:= count({PAYABLETCP.IDINV});
if howmany > 0 then inv1Array[1] +
if howmany > 1 then ', ' + inv1Array[2] +
if howmany > 2 then ', ' + inv1Array[3] +
if howmany > 3 then ', ' + inv1Array[4] +
if howmany > 4 then ', ' + inv1Array[5];
inv1Array[1];

Last line of the text is meant for displaying the first value in array.

On running the report I get following error message:
"A subscript must be between 1 and the size of the array"

I tried to insert a statement as = "redim inv1Array[3]"

but the same error message appears. It seems "redim" is not accepted.

In the subreport I created a formula with following text to display the array:

whileprintingrecords;
shared Stringvar array inv1Array;
inv1Array[1];

The error still remains.
I am stuck up.

 
Hi,
Can you explain the contents of {PAYABLETCP.IDINV}?
Is it an array?
This code:
if howmany > 0 then inv1Array[1] +
if howmany > 1 then ', ' + inv1Array[2] +
if howmany > 2 then ', ' + inv1Array[3] +
if howmany > 3 then ', ' + inv1Array[4] +
if howmany > 4 then ', ' + inv1Array[5];

does not create a new array or any new elements in the array ( that are no assignment operators).
Also if the Count = 0, your inv1Array[1] would cause the error since there is no such element.
It is also hard to see what you are trying to do so could you explain what you are trying to accomplish..
( Ideally, with sample input and output desired)




[profile]

To Paraphrase:"The Help you get is proportional to the Help you give.."
 
Try sharing complete information, this "In the main report I created a formule as follows to create a shared array:" doesn't say WHERE in the report the array is, as you might understand, this in the report header vs. details will produce very different results.

In general I suggest that people NOT define architecture, rather state what they have and what they want, which works out best for everyone as we don't have to guess at basic information and start a blog ;)

It appears that you misunderstand how Crystal works, it is a banded report writer, and formulas containing:

inv1Array:={PAYABLETCP.IDINV};

will simply place the current value for that field into the array in the first position.

I'd guess what you 2want is something like the following in the details section:

WhilePrintingRecords;
shared stringvar Array inv1Array;
redim preserve inv1Array [ubound(inv1Array)+1];
inv1Array[ubound(inv1Array)+1] :={PAYABLETCP.IDINV};

This will build the array out for each row.

Then you can reference any line of the array using:

WhilePrintingRecords;
shared stringvar Array inv1Array;
inviarray[X] // where X is the index of the element you wish to display.

Since you didn't bother to even post your software version, you may discover that this doesn't work either.

In general, try posting:

Crystal version
Database/connectivity used
Example data
Expected output

Using subreports and arrays are generally a bad idea as they degrade performance.

-k
 
Hi, Turkbear, thanks for the reply. Following details may also help you to analyse my problem.

Dear synapsevampire,
Thanks for reply. You have almost read my mind. You have given me right solution. Unfortunately it is not working (as you suspected) due to different version probably lower. I am working on Crystal Report Version 7 using ODBC connectivity, Database MS SQL.

I modified the formula text in main report as follows which does not show any syntax error.

numbervar InvCount:= count({PAYABLETCP.IDINV});
WhilePrintingRecords;
shared stringvar Array inv1Array;
if InvCount < 2 then inv1Array[1]={PAYABLETCP.IDINV};
if InvCount < 3 then inv1Array[2]={PAYABLETCP.IDINV};
if InvCount < 4 then inv1Array[3]={PAYABLETCP.IDINV};
if InvCount < 5 then inv1Array[4]={PAYABLETCP.IDINV};

am I correct in introducing the counter?

When I tried following syntax for detail section visibility in sub report, it gives syntax error after running report as "a subscript must be between 1 and the size of the array":

WhilePrintingRecords;
booleanvar X:= {APTRANSdet.IDINVC} in shared stringvar Array inv1Array[1];
if X= false then true;

Now I think you are in better position to help me.
 
You didn't initialize the arry to any size, of course it will error on you.

Dimension your array accordingly, as in:

numbervar InvCount:= count({PAYABLETCP.IDINV});
WhilePrintingRecords;
shared stringvar Array inv1Array[10];
if InvCount < 2 then inv1Array[1]={PAYABLETCP.IDINV};
if InvCount < 3 then inv1Array[2]={PAYABLETCP.IDINV};
if InvCount < 4 then inv1Array[3]={PAYABLETCP.IDINV};
if InvCount < 5 then inv1Array[4]={PAYABLETCP.IDINV};

This will default to a size of 10. CR 7 is very old and I don't recall it's many shortcomings, so it may be this isn't how you do so, in which case hit F1 and see how to size it, but I think this was correct then as well.

It's a shame that you're unwilling to post:

In general, try posting:

Crystal version
Database/connectivity used
Example data
Expected output

As previously requested.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top