Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Collections

Status
Not open for further replies.

heidegger2050

Programmer
Jun 13, 2007
4
US
I am new to VBA .. I am trying to modify Items in a Collection.. but I am having a hard time .

This is an example of what I mean ..

Sub Main()

Dim Cell_Matrix As New Collection
Dim Cell_01 As New Collection
Dim Cell_01_Occupancy As Boolean

Cell_01_Occupancy = False

Cell_01.Add Item:=Cell_01_Occupancy, Key:=CStr(1)
Cell_Matrix.Add Item:=Cell_01, Key:=CStr(1)

MsgBox Cell_Matrix(1).Item(1)

'I cant make this work
'Cell_Matrix(1).Item(1) = True

'MsgBox Cell_Matrix(1).Item(1)

End Sub

Your help would be greatly appreciated !
 



Hi,

What is your purpose for using Collections?

There are THREE methods for Collections...
[tt]
Add - Adds a member to a Collection object.
Remove - Removes a member from a Collection object.
Item - Returns a specific member of a Collection object either by position or by key.
[/tt]


Skip,

[glasses] [red][/red]
[tongue]
 
Thanks Skip

I am storing different data types in the collection. But I also want to modify the contents of the collection later. I know the 3 methods and the clear method but couldn’t use them to modify the contents of the collection.

-H
 
Thanks again Skip,

I tried that already, but since the collection (The Cell in the code) is passed to a function that modifies it, I always get nothing in the MsgBox after removing and adding to it again.
The code should give me a True in the MsgBox but it gives me an empty MsgBox instead?!
If I do not pass it to the function, it works fine .. but I need to use the function ..

Here is the code:

Function Draw_Component(Geometric_Set, Cell, Name)

Dim Cell_Occupancy_New As Boolean
Cell_Occupancy_New = True

MsgBox Cell_Occupancy_New

Cell.Remove (4)
Cell.Add Item:=Cell_Occupancy_New, Key:=CStr(4)

MsgBox Cell.Item(4)

End Function

Thanks Again !
 
Hi Skip,
I found the problem.. I was adding it by key .. but deleting it by index .. your second post was the answer .. THANKS !!

-H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top