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

Arrays in Crystal 9

Status
Not open for further replies.

pmenonsmitka

Programmer
Jan 25, 2005
7
US
Crystal Version : 9
Database Connectivity : Oracle Server to Oracle 8i database

Trying to put all the values of of a database field into an array in Crystal.

What I have so far :

numberVar cnt_interval := DistinctCount ({PMSEQUENCE.INTERVAL}, {PM.PMNUM});
NumberVar i;
numberVar array interval_arr;

For i := 1 To cnt_interval Step +1 Do
(
interval_arr := {PMSEQUENCE.INTERVAL}
);

I just can't find the documentation for the correct syntax anywhere.

Help!!

Thanks :)
 
Using Arrays is usually very inefficient for this purpose, I urge you to post requirements instead:

Example data
Expected output

It looks like your intent is to load it with distinct values, hard to say, the text says all, but you reference distinctcount.

Keep in mind that you don't use the recordset in Crystal like you might in a language, you do so in the appropriate section, on a row by row basis.

Ayway, the following will fill an arry at the details level:

StringVar array interval_arr;
redim preserve interval_arr[ubound(interval_arr)+1];
interval_arr[ubound(interval_arr)]:={Customer.Customer Name};
join(interval_arr,",")

This inserts a value from every row into an array (I used Join to display the output), so you'd use it in the details section.

You might want to use something like:

StringVar array interval_arr;
if not({Customer.Customer Name} in interval_arr) then
redim preserve interval_arr[ubound(interval_arr)+1];
interval_arr[ubound(interval_arr)]:={Customer.Customer Name};

to get distinct values.

I used a string, you can change to numeric if need be, however extracting all of the numerics at once is more complicated (can't use Join).

-k
 
Actually, what I'm trying to do is rather complicated.

For every row in the details section, I'm trying to insert all the values of table.field ({PMSEQUENCE.INTERVAL}) into the array interval_arr.

By doing this, I'm able to go through the array and perform a calculation and come up with one value related to the row in the details section. I hope I'm explaining it correctly. Therefore, I loop through the array in the formula and the formula comes up with a value result for that particular row in the details section.

The suggestion you've made above, lets me put all the rows displayed in the report into an array which is not what I want.

Is there a way for me to loop through the database field regardless of whether it is displayed in the details section :

Jobplan Interval Needed
-------------------------------------
JP#1 value as calculated by the formula with the loop

The JP#1 value of the Jobplan field is displayed in the details section of the report.

Please let me know if I need to elaborate more.

Thanks,
 
Sorry, I misunderstood, that's fairly simple.

The difficulty is that you haven't described what delimiter is used within the field to be broken into an array.

Here's the trick, though:

If the data is comma delimited, then try:

StringVar array interval_arr:=split({table.field},",");

Now you have an array called interval_arr.

To check for a value in it, use:

if "My string" in interval_arr then
"it's there"
else
"nope"

To individually pull values using the subscript, use:

interval_arr[1]

Which would pull the first value

-k
 
Sorry:) but that is still not it.

PMSEQUENCE is the table and INTERVAL is the field in the database table. PMNUM and JPNUM are also fields in the table.

Here is the hierarchy :
PMNUM
JPNUM
and every JPNUM has an interval value.

Now, for every JPNUM in the details section I run a formula in which I want to insert every value of INTERVAL for a PMNUM into an array.

Example : PM1 (a PMNUM value) has 3 JPNUM's namely : JP1, JP2 and JP3 and each of them has an interval value of 1, 3 and 6 respectively. This leads to the conclusion that PM1 has 3 interval values related to it in the database table.

Table looks like this :
PMNUM JPNUM INTERVAL
---------------------------
PM1 JP1 1
PM1 JP2 3
PM1 JP3 6

Now, I want to be able to insert the values 1,3 and 6 into an array to calculate a formula for JP1 and the same for JP2 and so on and so forth.

Crystal Set up :

PMNUM (Group Section)
JPNUM (details section) and then the formula is calculated for each JPNUM in the details section.

To conclude, the field INTERVAL itself is not separated by any delimiter.

Hope is a better explanation of what I'm trying to do :)

Thanks,

 
Can you post what calculation you want to do with these intervals? there might be a simpler solution than using arrays
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top