Examples: IsElement function

' Use IsElement to determine whether
' the user correctly identifies a list tag.
' Declare a list to hold employee Ids.
Dim empList List As Double
Dim empName As String, Id As Double
Dim found As Boolean
' Create some list elements and assign them values.
empList#("Maria Jones") = 12345
empList#("Roman Minsky") = 23456
empList#("Joe Smith") = 34567
empList#("Sal Piccio") = 91234
' Ask the user to identify the list item to be removed.
empName$ = InputBox$("Which employee is leaving?")
' Check to see if empName$ corresponds to a list tag. 
' If not, display a message and stop. Otherwise, 
' validate the employee's Id.
' If everything checks out, remove the item from the list.
If IsElement(empList#(empName$)) = TRUE Then
   Id# = CDbl(InputBox$("What's " & empName$ & "'s Id?"))
   found = FALSE          ' Initialize found to 0 (FALSE)
   ForAll empId In empList#
      If empId = Id# Then
         found = TRUE     ' Set found to -1 (TRUE).
         If ListTag(empId) = empName$ Then
            Erase empList#(empName$)
            ' Verify the removal of the list element.
            If IsElement(empList#(empName$)) = FALSE Then
               MessageBox empName$ & _
                  " has been removed from the list."
            End If
         Else
            MessageBox "Employee name and Id do not match."
         End If
         ' No need to look farther for Id, so get out
         ' of the ForAll loop.
         Exit ForAll
      End If
   End ForAll
   If found = FALSE Then
      MessageBox "Not a valid employee Id."
   End If
Else
   MessageBox "We have no such employee."
End If