Manage Learn to apply best practices and optimize your operations.

American business forms

This tip describes using IsElement to test whether your new value is a list tag or not.

If you have ever had to check if a value is part of a group of allowed values, but dread the thought of having to setup and array, and then do the looping to check if your new value is in the array, this shortcut is for you, just use a list so that you can use IsElement to test whether your new value is a list tag or not.

I had a case where I wanted to perform certain actions in a database QueryDelete event, but certain people should be excluded from the actions.

So, I could have created an array with the users who should be excluded, in which case the code snippet may have looked something like this.

Dim names() As String

 Redim names(0) Names(0) = "Joe" . . Redim Preserve names(1) Names(1) = "Jill" . . Redim Preserve names(2) Names(2) = "Jocko" user = session.CommonName Forall n in names If n = user then ' a match was found Continue = True Exit Sub end if end forall

But since I don't enjoy Redim, and I really don't enjoy embedding of If's and For's, instead the above code became the following:

 Dim allowed List As String allowed("Joe") = "Worker" allowed("Jill" ) = "Worker" allowed"Jocko") = "Boss" user = session.CommonName If Iselement(allowed( user )) = True Then ' match was found Continue = True Exit Sub End If

In the above example, the value I store in the list element really does not matter, I just care about the list tag so that I can use Iselement. I also remove the overhead associated with Redim's if I do not know how many names I will be adding. Finally, I reduce one level of nesting making the code much cleaner.

Dig Deeper on Domino Resources - Part 2

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...