EDIT: The problem is probably linked to this line:
stationUnits.Add newTag.Unit, New Collection '[Dictionary].Add key:=[String], item:=[Collection]
I'm having a problem with the Scripting.Dictionary.Exists(key) method refusing to evaluate as false so that I can anticipate whether or not I need to create a new collection for it. Does anyone see what I'm missing?
Interesting points:
- The MsgBox in the Let ID property prints FALSE
- The debugger shows the correct value (string) for newTag.Unit
- I've tried using .Exists directly in the comparison (instead of calling the hasUnit property), there's no difference.
- At first I thought .Exists was not working at all, but through the .hasUnit property I'm watching it change from FALSE to TRUE. No keys have been added to the dictionary yet. ...why is it doing this?
''StationData Class
Private stationID As String, stationUnits As Scripting.Dictionary
Public Property Let ID(id_string As String)
stationID = id_string
Set stationUnits = New Scripting.Dictionary
stationUnits.CompareMode = BinaryCompare
MsgBox stationUnits.Exists("blah")
End Property
Public Property Get ID() As String: ID = stationID: End Function
Public Property Get nUnits(): nUnits = stationUnits.Count: End Property
Public Function addTag(ByVal newTag As TagString)
If Not newTag.isValid Then
Exit Function
End If
If Not newTag.Station = Me.ID Then
Exit Function
End If
If Not Me.hasUnit(newTag.Unit) Then
'If the unit key has not already been added, add it along with a new collection
stationUnits.Add newTag.Unit, New Collection
stationUnits.Item(newTag.Unit).Add (newTag)
Else
'If the unit key already exists, add a new item to its collection.
stationUnits.Item(newTag.Unit).Add (newTag)
End If
End Function
Public Property Get hasUnit(ByVal uString As String) As Boolean
hasUnit = stationUnits.Exists(uString)
End Property