Can someone tell me why the following code is always returning false? I have to populate a dictionary but if the key is already in the dictionary I should not. A list called MagazineTitles contains details of all the keys in the dictionary and I am trying to use a for each loop and if statement to determine the keys prior to insertion but even if the key is not in the dictionary or list I keep getting false returned and the item is not inserted.
Code:Public Function addMagazine(ByVal aMagazine As EMagazine) As Boolean
'Preconditions: none
'Postconditions: If the title of aMagazine is not contained in MagazineTitles
'then aMagazine is added to the dictionary of magazines, with its title as
'key, and True is returned. Otherwise False is returned.
'Complete the code here
Dim result As Boolean
For Each title As String In MagazineTitles
If title = MainForm.nameTextBox.Text Then
result = False
Else
fMagazines.Add(MainForm.nameTextBox.Text, aMagazine)
result = True
End If
Next
Return result
End Function