@While loop with array
@While loop with array
(OP)
Hi,
I'm working with Lotus Notes 9 (IBM Notes).
I'm trying to check for a value in a series of fields using a loop. There may be an obvious answer here but I can't find it.
The FIELD expression is giving me trouble. How do I refer to a field using an array of field names?
A test of the loop successfully added all the array elements to the "fullNote" variable and displayed them. Adding the FIELD() reference caused the failure.
I'm working with Lotus Notes 9 (IBM Notes).
I'm trying to check for a value in a series of fields using a loop. There may be an obvious answer here but I can't find it.
CODE --> LotusNotes_Formula_Language
n := 1; @While(n <= @Elements(myNames); @If( FIELD(myNames[n]) ="4" ; fullNote := fullNote + ", " + myNames[n] ; ); n := n + 1);
The FIELD expression is giving me trouble. How do I refer to a field using an array of field names?
A test of the loop successfully added all the array elements to the "fullNote" variable and displayed them. Adding the FIELD() reference caused the failure.
RE: @While loop with array
Generally, using FIELD is done like so : FIELD fname := x;
FIELD is used for affecting a value to a document field. You are comparing, so you don't need it. When you compare field content, just using the name of the field works fine.
I have never needed to work with an array in Formula, I prefer using LotusScript for that, but I would suggest the following modification :
CODE
Let me know how that goes :)
Pascal
I've got nothing to hide, and I demand that you justify what right you have to ask.
RE: @While loop with array
You're proposed solution doesn't work. Suppose my first field's name is "firehazard" and it contains "4".
When I use "firehazard" in the code the system recognizes it as a field and compares the field's value to "4" in the @IF statement resulting in the true condition.
When I use "myNames[1]" the system recognizes it as an array variable and compares the variable's first element, "firehazard", to "4" in the @IF statement resulting in the false condition.
Excel has the INDIRECT function which tells the system that the variable contents cited are to be treated as a range. Does Lotus notes have a similar function or procedure to pass a variable value as a field name?
I'm hoping you know a solution to this problem. Thanks.
RE: @While loop with array
In the myNames field (number, multivalue), I gave it a default of 1:1:1 - meaning three values of 1.
In the test field, I created a translation formula as follows :
CODE
When I refresh the document, the test field gets filled with 3, which is the correct answer and demonstrates that the code works.
I'm sure you can adapt this example to your scenario.
Pascal.
I've got nothing to hide, and I demand that you justify what right you have to ask.
RE: @While loop with array
In your example myNames is the name of the database field and the results are as expected.
In my case myNames is the name of an array variable within a report. The report is pulling values from the database where there is no field named myNames. The database is not one that I made, nor am I able to revise it so that I can use your code to get the information I need in the way you have done.
To further illustrate what is happening when my report runs, see below. I have shown a short version of the myNames array which will contain 54 different field names.
CODE -->
At n=1 the @IF statement is comparing the array value of myNames[1], "Firehazard", to the string value "4". Condition false.
At n=2 the @IF statement is comparing the array value of myNames[2], "Fireresponse", to the string value "4", etc. Condition false.
The value in the fields of the database may be any one of the following, "X", "1", "2", "3", "4", "5", "6", "7", "8" or "9".
I am hoping to loop the @IF statement so I don't need to repeat it manually for the 54 different fields I want to check. The conditions where the field value is any of "1", "2", "3" or "4" needs to be identified by the code therefore I will need 116 instances of the @IF statement unless I can iterate it in a loop.
Ultimately I need a function that will allow the code to use the underlined instance (in the code above) of myNames[n] as a field reference where the value of myNames[n] is the field name to get the values from.
RE: @While loop with array
I found the function I need, @GetField.
CODE -->
Thanks for your help. Your time is appreciated.
RE: @While loop with array
If I had realized that, I would have pointed you there sooner.
I'm glad you solved your problem. Given the scenario you outline, I would have definitely done it in LotusScript :).
In any case, happy coding !
Pascal.
I've got nothing to hide, and I demand that you justify what right you have to ask.
RE: @While loop with array