Update an item in a vb6 collection

I never got an answer to this question:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_28503895.html

So after doing some investigating I am trying to modify some code from vbHelper

http://www.vb-helper.com/howto_custom_collection_with_for_each.html
I have been trying to find a way to update a record thats been added to the collection to no avail.
How can this be done ?
For-EE-Collection.zip
isnoend2001Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
If you add the item to the collection and include a key. You can just do MyCol(<key value>) = "New Value"
0
isnoend2001Author Commented:
Thanks martinliss
My plan was to use the company name as the key as it would be extremely rare for 2 companies  with same name bidding on the same roof.
in setting the values i do this:
Set m_RoofCompany = New RoofCoCollection

    Set RCo = New RoofCo
   
    With RCo
.CompanyName = txtCompany
When i try to add a value i get an error
0
Martin LissOlder than dirtCommented:
I was wrong you have to remove the item that you want to "change" and then add the "changed" item.

Dim m_RoofCompany As Collection
Dim lngIndex As Long

Set m_RoofCompany = New Collection

' Build the collection
m_RoofCompany.Add "Apple", "Apple"
m_RoofCompany.Add "IBM", "IBM"
m_RoofCompany.Add "Samsung", "Samsung"

'List its contents
For lngIndex = 1 To m_RoofCompany.Count
    Debug.Print m_RoofCompany(lngIndex)
Next

'Change one of them
m_RoofCompany.Remove "Samsung"
m_RoofCompany.Add "Microsoft", "Microsoft"

'List its contents again
For lngIndex = 1 To m_RoofCompany.Count
    Debug.Print m_RoofCompany(lngIndex)
Next

Open in new window


And as for there being companies with the same name, If you add the item with a key, you'll get a 457 error that you can trap if there's a duplicate.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

isnoend2001Author Commented:
thanks martinliss
I maybe not going about this correctly using a collection
Each Company will have all those textboxs, eg; Bid Amount, Phones
' Build the collection
m_RoofCompany.Add txtCompany, "Company"
m_RoofCompany.Add txtAddress, "address"
m_RoofCompany.Add txtCity, "City"
Each company will have different information, maybe i should only supply a key with company only
0
Martin LissOlder than dirtCommented:
Add a class module that contains all the kinds of info you want to store in the collection like this

Class1
Option Explicit

Public Company As String
Public Address As String
Public City As String

Open in new window


Then
Dim m_RoofCompany As Collection
Dim lngIndex As Long
Dim ci As Class1

Set m_RoofCompany = New Collection
' Build the collection
Set ci = New Class1
ci.Company = "Apple"
ci.Address = "1 Infinite Loop"
ci.City = "Cupertino, CA"
m_RoofCompany.Add ci, "Apple"

Set ci = New Class1
ci.Company = "IBM"
ci.Address = "1001 E Hillsdale Blvd"
ci.City = "Foster City, CA"
m_RoofCompany.Add ci, "IBM"

Set ci = New Class1
ci.Company = "Samsung"
ci.Address = "123 some street"
ci.City = "Any city"

m_RoofCompany.Add ci, "Samsung"

'Show the contents of one of them
Debug.Print m_RoofCompany("IBM").Company
Debug.Print m_RoofCompany("IBM").Address
Debug.Print m_RoofCompany("IBM").City

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isnoend2001Author Commented:
Thanks martinliss i think i got it
0
Martin LissOlder than dirtCommented:
As always I'm glad I was able to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.