[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Update an item in a vb6 collection

Posted on 2014-08-28
7
Medium Priority
?
988 Views
Last Modified: 2014-08-28
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
0
Comment
Question by:isnoend2001
  • 4
  • 3
7 Comments
 
LVL 50

Expert Comment

by:Martin Liss
ID: 40291745
If you add the item to the collection and include a key. You can just do MyCol(<key value>) = "New Value"
0
 

Author Comment

by:isnoend2001
ID: 40291765
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
 
LVL 50

Expert Comment

by:Martin Liss
ID: 40291810
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:isnoend2001
ID: 40291837
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
 
LVL 50

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 40291855
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
 

Author Closing Comment

by:isnoend2001
ID: 40291858
Thanks martinliss i think i got it
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 40291861
As always I'm glad I was able to help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question