-1

What happens if you try to add an item to a Collection that already exists in the Collection?

Let's say you have a Collection full of integers and you try to add an integer that is already in the Collection.

CJ7
  • 22,579
  • 65
  • 193
  • 321
  • 1
    You might be interested in [how to detect whether the key has already been used](http://stackoverflow.com/questions/40651/check-if-a-record-exists-in-a-vb6-collection) – MarkJ Jan 24 '12 at 13:39

2 Answers2

2

Simply put if you add an item to a collection twice, it will be in the collection twice. If you add it with a key then that needs to be unique.

Deanna
  • 23,876
  • 7
  • 71
  • 156
0

If you try to add something with the same key as a key already in the collection, it throws an error (docs). You can add the same object to a collection twice as long as you use different keys for it.


Side note: Microsoft ended all official support for the VB6 development environment nearly four years ago. The runtime remains supported at least through Windows 7 (e.g., so existing apps continue to run). See this other question and its answers for more details.

Community
  • 1
  • 1
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • 1
    Apparently the VB6 runtimes were included in the Win8 Developer Preview, and in any case it wouldn't be hard to include them in an install package. I don't think it's all doom and gloom for VB6 apps, just yet. – CJ7 Jan 24 '12 at 10:08
  • Yes, the IDE will have problems. I haven't been able to install it on Win 7 yet, although others (including MS) claim it is supported. – CJ7 Jan 24 '12 at 10:59
  • 1
    @CraigJ The VB6 IDE on Windows 7 is [discussed on this other question](http://stackoverflow.com/questions/2339536/has-anyone-had-success-with-visual-studio-6-on-windows-7) – MarkJ Jan 24 '12 at 13:30
  • 2
    +1 Not least for linking to the docs! But the side-note doesn't belong in this answer. Contribute to the question about [whether VB6 will be supported on Windows 8](http://stackoverflow.com/questions/4221661/vb6-running-on-windows-8) if you feel you have more to add. Please read the existing answers and comments first though, as I don't see anything new in your sidenote. – MarkJ Jan 24 '12 at 13:34
  • 1
    I'll add a comment. I feel that posts like this are unproductive and argumentative. – Bob77 Jan 26 '12 at 15:21
  • @BobRiemersma: Thank you for commenting. The OP asked what happens when you add an item to a collection twice. I told him, and linked to the documentation. I also mentioned that VB6's dev env has been completely unsupported for nearly four years. I'm not arguing whether it should or shouldn't be used, I was just making sure the OP and others finding the question know that (from his comments, it seems the OP does). I'm not remotely seeing how doing so is argumentative, or how answering his question in the first instead is unproductive. – T.J. Crowder Jan 26 '12 at 16:58