Is it possible to re-index a Map collection after removing an item ?
I am iterating through a database field to find the first match to a Map item, then removing the map item. It appears that leaves a hole in the map collection. Keys then are 0,2,3,4 etc. with no number 1.
Reindexing to fill the hole would simplify my code. Can that be done?
I don't know much about map handling, but I can suppose you can simply create a new map, filling it with the objects remained after deletion and re-indexing them. Then simply set the oldMap=newMap. Think this could work.
I'm replacing a collection from VB6. In VB6 when you removed an item from a collection, it reindexed the collection. I'm using a map to replace it and there is no index. But, the reply from MC73 got me going in this direction and the following sub works for me. It just moves all the items up one position. Then I have a map.getvalueat(0) again.
Sub ReIDXMap(sMap As Map)
'Remove the first item in Map so we cannot use it again
'manually reindex the Map to fill the hole
If sMap.size > 0 Then
Dim NewMap As Map
NewMap.Initialize
Dim MapIndex As Int
For MapIndex = 1 To sMap.size-1
NewMap.Put(MapIndex-1, sMap.GetValueAt(MapIndex))
Next
sMap.Clear
For MapIndex = 0 To NewMap.size-1
sMap.Put(MapIndex, NewMap.GetValueAt(MapIndex))
Next