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!

Determining Array Element Position

Status
Not open for further replies.

cakoliver

Technical User
Mar 9, 2001
28
US
I need to keep track of several numeric values for a variety of different related string values. Under normal conditions, a cross tab would probably work. For a variety of reasons, cross tab isn't the answer.
Essentially, I'm keeping track of things like Original Estimate, JTD cost etc. for a list of cost codes. When reading a record, I'd like to check Array A(which contains the cost codes) to see if the cost code exists and in what position. I would then increment the corresponding element in ArrayB(which would contain Original Estimate) and ArrayC(which would contain JTD Cost)
My problem is that I can't find the operator that tells me which Array element/position a given value occupies. The IN operator will tell me if the value exists, but I need to know where(what position) it is in. Am I missing something here? Is there such an operator? I'm using Crystal Version 8, Developer Edition
 
I looked for one of these the other day, and I don't think it exists. The only way I know of to do this is to write a loop that checks each position in turn until it finds a match.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Expert's Guide to Formulas / Guide to Crystal in VB
- tek@kenhamady.com
 
Here is the method I use to obtain the position.

stringvar array tarray:=["5","4","3","2"];//your array
stringvar check:= "4";//your field
numbervar loops:=ubound(tarray);
numbervar k;
numbervar posit;

for k:=1 to loops do(
if tarray[k]=check then
(posit:=k;
k:=loops));
posit


Mike
 
The array approach above would work, but consider creating a Table/Query/View to hold the same information, allowing an outer join to act as the lookup mechanism.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Ken,
Thanks for the reply, at the very least I feel better knowing that you couldn't find it either. Although, finding out there was an operator that I couldn't find would have been good as well.

Mike,
Thanks for the code, I'll be giving that a try.

IDO,
I'm not so sure I understand your reply. What is it I would create / maintain from within the container report whereby I could interrogate/modify/increment & clear the equivalent of multiple related arrays.

Again,
Thanks to all of you folks. Don't know what I'd do without TekTips
 
If you use Access as the data source, you would create a query (called View in other DBMSs such as SQL Server, Oracle, Sybase, DB2).

That query would generate the cost codes and their related information as if the information was in a physical table.

You can then add that query (as if it was a table) to your report and do an Outer Join to lookup the associated values.

hth,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top