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

Position in Array

Status
Not open for further replies.

CrystalizeCanada

Instructor
Mar 4, 2009
141
CA
Hi,

I'm trying to find the position of an item in array, say for example "Alley Cat Cycles" in an array of customers say
["Blazing Saddles", "Acme Bikes", "Alley Cat Cycles", "Barry's Bikes]. I want to get the answer 3 here as it's the customer is the third element in the string array. I can get this succesfully with a formula which uses a loop. I'd like to do it without looping as this may take some time - heres the example below (copy and paste it will work as it doesn't refer to any database fields):

//PURPOSE OF FORMULA: Identify position of customer in string array
//VARIABLE DECLARATIONS:
StringVar Array MyStringArray:=["Blazing Saddles", "Alley Cat Cycles", "Acme Bikes", "Barry's Bikes"];
StringVar Array MyCustomer:="Alley Cat Cycles";
NumberVar i;
//FORMULA RESULT:
For i:= 1 to Count(MyStringArray) do
if MyCustomer =MySTringArray then exit for;
i //this will tell me 3

Is there a way to do this without a loop?

Tx

Gordon BOCP
Crystalize
 
Hi dgillz,

Speed is the problem - this can end up being quite slow cos of all the looping - a bit like subreports. I guess I'm being a little fuzzy.

Tx


Gordon BOCP
Crystalize
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top