Work with the Collection Items

Visual LANSA

Work with the Collection Items

Individual items in the collection are accessed using a For/EndFor loop.

The click event of the Show button iterates through the collection referencing each entry in the collection by using a For/EndFor loop to retrieve the value of  #GiveName and #Surname of the individual employees to a message box:

For Each(#Employee_GiveName) In(#Employee) Key(#Employee_SurName)
Use Builtin(MESSAGE_BOX_ADD) With_Args('Employee' #EMPLOYEE_GIVENAME.VALUE #EMPLOYEE_SURNAME.VALUE 'was found in the collection.')
Endfor

 

In the above note that:

  • The For/EndFor loop specifies a name for the Key (#Employee_SurName) to access the key of the current component each time the variable name (#Employee_GiveName) is referenced. In this way the value of the #Surname field can be retrieved to the message.

Example 2: Collections do not Need to Be Keyed by Index