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

2D Arrays 1

Status
Not open for further replies.

f0z

Programmer
Jan 10, 2003
48
US
how do i define a 2d array in a crystal formulas? or is it even possible.

any help is greatly appreciated.

foz
 
The short answer is that Crystal doesn't support 2D arrays. Share what you need to do and I am sure someone here can provide an alternate solution.

~Brian
 
I'm designing a report that calculates the faxing costs for the company.

Call cost being dependant on, time of day, destination number and duration of call. I'd decided to create formula to determine time of day and another to categorise the destination number(ie local, national, etc...). The duration of the call is taken from a field in a table.

I was going to have both of these functions return a number and these numbers where going to be passed as indexes to my 2D array. The value at this location being the rate per second for the appropriate destination and time of day.

But if I cant use my 2D array I guess i've to look at it from a different angle.

Something along the lines of getting the function that determines what category the call goes into (local, national, international, etc...) to return a rate depending on the time of day. This would bypass the need for an array but if i want to change all the rates it gets messy.

anyway all ideas are welcome.

cheers
foz
 
you can still use a pseudo 2D array...just make it 2 separate one dimension arrays

StringVar array Index := [ "","","","" ];
StringVar array Value := [ "","","","" ];

Just fill them as you normally would a 2 dimensioned array

Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Jim:

Having 2 different arrays is very different than having a 2D array. A 2D array is an array of arrays.

foz:
If your rates table can't be joined to your calls table, then you could use 3 arrays to hold your rates. One for array each for local, national, and international. There could be 24 elements for each array; each element holding the rate for that hour. You could populate these arrays in a subreport that would reside in the Report Header.
In your formula to determine the charge, you could determine the destination, so that you know which array to use to find the rate, then calculate the charge.

~Brian
 
Brian - It may not be as convenient....but 2 separate single arrays can do the job of one 2 dimensioned array...as long as you pay attention to what you are doing.

For a very simple example:

StringVar Array Cars := [ "Ford","Chevy","Oldsmobile" ];
StringVar Array Price := [ "12,000", "15,000", "10,000" ];
numbervar counter;

//find the 10,000 car

For counter := 1 to 3 do
(
if Price[counter] = "10,000" then
exit for;
);

"The 10,000 car is " + Cars[counter];

the above 2 arrays could have been a single 2D array for this example. {shrug}

Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
cheers for all the suggestions.

brian:
basically there are 31 call types and 3 different call rates for each call type. the array would have been a 3*31 array. so 3 1d arrays might work.

For the moment i've bypassed the arrays, just because i need to get this done fairly soon.

Question:
If i get my calltype formula to return a string, name of the array for that call type, is there a function equivalent to the javascript eval()?

cheers foz
 
Jim:

If you wanted to mimic a 2D array, you would need an additional array for each of your items in your first array. My only point was that you can't truly mimic a 2D array with just 2 arrays.

foz:

I am not familiar with the javascript function eval(). If you can give me an explanation, I can let you know what might be the equivilant in Crystal.

~Brian
 
Bdreed - I fail to see the necessity of a third array...show me this need by example

Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Jim:

f0z stated that he thinks he could use 3 arrays to accomplish what he needs, not me. I think that 3 arrays would not accomplish what he is trying to do.

There are 31 different call types, and 3 different rates (depending on time of day) for each call type.
If Crystal supported 2D arrays, you'd create an array that was 31 by 3. Your first element would be the call type (local, national, etc.) and then within each of those, you would have the 3 rates. Element 1 might mean Midnight to 8am, 2 might mean 8am to 6pm, and 3 might mean 6pm to Midnight.

If you tried to use just 2 arrays, you would only have one rate structure. The rates are different for each call type. To mimic the 2D array, you would need 31 or 32 arrays. At that point, it is probably better to seek an alternate method, if possible.


~Brian
 
f0z:

I think you ought to take a look at trying to have your rate returned in your recordset and abandoning the whole array thing. Your arrays would end up being hard coded and would require a manual effort to update them whenever they changed.

If you can use a Stored Procedure, you will save yourself alot of effort down the road.


~Brian
 
i see...sorry...I didn't read closely enough....we have nothing to argue about...[grin]

basically there are 31 call types and 3 different call rates for each call type. the array would have been a 3*31 array. so 3 1d arrays might work.

How about this approach. A string is considered an array in Crystal. I don't know what the format of the CallRate is but it can be made into a string of a standard length....

So...you don't want to hard code this because of the maintenance of the report...a stored proceedure would work perhaps....but you could also do it in a subreport in the main report header

in this subreport you would create a shared string array with each string having a very defined structure
for example

| 50 chars for location | 10 chars Rate1 | 10 chars Rate1 |10 chars Rate1 |

Rate1 would be the rate for say Midnight to 6AM
Rate2 would be the rate for say 6AM to 6PM
Rate3 would be the rate for say 6PM to Midnight

now in your main report when you are looking for a rate value you just loop through this array looking for the location in the first 50 chars (justified to the left & padded with blanks to 50) and then when you find it if you want Rate1 then you take ArrayInfo[x] [51 to 60]....or mid(ArrayInfo[x],51,10) if you like.

Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top