×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

@While loop with array

@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.

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

Greetings,

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

n := 1;
@While(n <= @Elements(myNames);
@If( myNames[n] ="4" ; fullNote := fullNote + ", " + myNames[n] ; );
n := n + 1); 

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

Pascal, bpeirson here. I can't access my first account so I set up an new account so I can respond to my own thread. Go figure!

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

I have just made a test scenario. In an empty database I created a form. On the form I created two fields, myNames and test.
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

n := 1;
a := 0;
@While(n <= @Elements(myNames);
a := a + myNames[n];
n := n + 1);
a 

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

Agreed, your code works as noted.

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 -->

myNames := "Firehazard" : "Fireresponse";
n := 1;
@While(n <= @Elements(myNames);
@If( myNames[n] ="4" ; fullNote := fullNote + ", " + myNames[n] ; "");
n := n + 1); 

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

Pascal,

I found the function I need, @GetField.

CODE -->

n := 1;
@While(n <= @Elements(myNames);
@If( @GetField(myNames[n]) ="4" ; fullNote := fullNote + ", " + myNames[n] ; "");
n := n + 1); 

Thanks for your help. Your time is appreciated.

RE: @While loop with array

I didn't realize that myNames contained the name of a field you needed to check the value of. Obviously, GetField is your solution.
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

If I need more help it is good to know someone is paying attention in this group. Thanks.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close