Remove an Element from an Array

Table of contents:

The RemoveElement function checks each element in an array for a target value. If the target value is found, that item is removed from the array.

How It Works

This function requires an array and target search value. The function loops through each element in the array and compares the value to the search string. If the values do not match, the element is added to a temporary array. If the values do match, it is skipped and thus not included in the array. After all elements are checked, the temporary array is returned with all references to the target search value removed.

Implementation

This function requires two parametersan array of values and the search value.

Function RemoveElement (varFromList As Variant, varTarget As Variant) As Variant

 '-----------------------------------------------------------------------
 ' Removes an element from an array.
 '-----------------------------------------------------------------------
 Redim ReturnArray(0) As Variant
 Dim i As Integer
 i = 0

 Forall varElement In varFromList
 Redim Preserve ReturnArray (i) As Variant
 If varElement <> varTarget Then
 ReturnArray(i) = varElement
 i = i + 1
 End If
 End Forall

 RemoveElement = ReturnArray

End Function

The following illustrates how the function could be called from an action button. In this example, the name "Tom" is removed from the array theTeam (see Figure 13.3). After the function call, the returned array will contain "Henry", "Mark", and "Steve".

Sub Click(Source As Button)

 Dim newTeam As Variant
 Dim theTeam (0 To 3) As String
 theTeam (0) = "Tom"
 theTeam (1) = "Henry"
 theTeam (2) = "Mark"
 theTeam (3) = "Steve"
 Msgbox Implode ( theTeam, ", "), , "Original Team"
 newTeam = removeElement ( theTeam, "Tom" )
 Msgbox Implode (newTeam, ", "), , "New Team"

End Sub

Figure 13.3. Remove an element from an array


Compare Two Arrays

An Introduction to the Lotus Domino Tool Suite

Getting Started with Designer

Navigating the Domino Designer Workspace

Domino Design Elements

An Introduction to Formula Language

An Introduction to LotusScript

Fundamentals of a Notes Application

Calendar Applications

Collaborative Applications

Reference Library Applications

Workflow Applications

Web Applications

Design Enhancements Using LotusScript

Design Enhancements Using Formula Language

View Enhancements

Sample Agents

Miscellaneous Enhancements and Tips for Domino Databases

Data Management

Security

Application Deployment and Maintenance

Troubleshooting

Appendix A. Online Project Files and Sample Applications

Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?



Lotus Notes Developer's Toolbox(c) Tips for Rapid and Successful Deployment
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
ISBN: 0132214482
EAN: 2147483647
Year: N/A
Pages: 293
Authors: Mark Elliott

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net