Getting index values with @Formula
I'm doing quite a lot of @Formula coding these days and I'm finding the "new" index capability of @Formula very helpfull. I know it was introduced in release 6 but I'm just starting to use it - old habits die hard.
In that connection I frequently have two arrays of data where I need to find the index of a key value ("Key") in the first array ("keys") and get then get the entry at the same index in the other array ("data"). I have found no ArrayGetIndex-like function in @Formula so I'm resorting to a @For-loop to find the correct index and then getting the value from the other array.
keys := @GetProfileField("MyProfile"; "Keys");
data := @GetProfileField("MyProfile"; "Data");
result := "";
@For(n:=1; n<=@Elements(keys); n:=n+1;
@If(keys[n] = Key;
@Set("result"; profile_kortlink[n]);
""
)
);
result
Anyone who knows of an easier way?
Re: Getting index values with @Formula
The only difference in my implementations is combining the two lists into one, because the two list might get out of sync. One list might have 5 elements and the other has 4 elements thus causing errors. The only issue is having a unique string (I choose %~%) to separate the values.
The only other thing you could as an exit for the @For loop.
Example:
REM {KeyData is stored in the following format Key%~%Data};
keyData := @GetProfileField("MyProfile"; "KeysData");
result := "";
@For(n:=1; n<=@Elements(keyData); n:=n+1;
@If(keyData[n] = @Word( keyData[n] , "%~%" , 1 );
@Set("result"; @Word( keyData[n] , "%~%" , 2 ) ) : n := @Elements( keyData);
""
)
);
result
Re: Getting index values with @Formula
keys := @GetProfileField("MyProfile"; "Keys");
data := @GetProfileField("MyProfile"; "Data");
n:=@Member(keys; key);
result:=@If(n=0; "not found"; data[n]);
@If(@IsError(result); "no data"; result)
Found in designer help, "Working with lists"
Or hav I misunderstood something?





