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?
No there is no other easier way that I know of. In 5 I implemented this using @SubSet, but the other developers would complain of the complexity.
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); "" ) ); resultWell, duh…
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?
Or you could try this:
keys := @GetProfileField(“MyProfile”; “Keys”);
data := @GetProfileField(“MyProfile”; “Data”);
@Replace( Key; keys; data )
Hi Mikkel
Get more reading:
«IBM Lotus Notes/Domino @Replace Explained»
«Learn the basics of the amazing but often-overlooked @Replace to manipulate lists in Lotus Notes/Domino applications»
available from http://doc.advisor.com/doc/15992#_comments AND/OR http://advisor.com/doc/15059