View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Rich Rich is offline
external usenet poster
 
Posts: 298
Default vba collection object in Excel

Thanks for the reply. I did try the variant array thing, but what I am
trying to do is to change (reassign) the value of the var through the
collection object:

ex:

Dim col As New Collection, i1 As Integer, i2 As Integer
i1 = 10
12 = 20
col.Add i1, "1"
col.Add i2, "2"

col1("1") = 15
debug.print i1 '--i1 value would be changed from 10 to 15 -- isn't there a
pass by reference thing in VBA where you can change the value of a var this
way?

I want i1 to now contain the value of 15 instead of 10. Is there a way to
achieve this?

Incase you care -- I have a I am creating a graph of dots based on numbers
from a row of cells (in Excel 2010 they have spark lines or something like
that which sort of does the same thing to a degree). If some of my dots
(Excel 2003) are like way off the boundaries that I specify (the boundaries
would be a vertical difference of like 60 units between dots -- if 4 dots are
further than 60 units from the average of the other dots - I exclude those
dots), I want to not show those dots. But a range of dots (12 dots total)
may have 4 dots that are close together (vertically) and then 8 more which
are at a significantly different level (vertically) but are close together.
I want to display the 8 dots that are close together (rather than squishing
together the dots - keep the perspective to actual perspective unlike the
sparklines).

.. . . .


. . . . . . . . <--display these dots


"Ryan H" wrote:

You are trying to store Inetger Data Types as Objects in a Collection, no
good. Why don't you just put your integers into an Array instead.

Dim MyArray(3) As Variant
Dim i1 As Integer
Dim i2 As Integer
Dim i3 As Integer
Dim i4 As Integer

i1 = 10
i2 = 20
i3 = 30
i4 = 40

MyArray = Array(i1, i2, i3, i4)

or

MyArray(0) = 10
MyArray(1) = 20
MyArray(2) = 30
MyArray(3) = 40

Hope this helps! If so, click "YES" below.


--
Cheers,
Ryan


"Rich" wrote:

I haven't worked with vba collection objects for a while and have sort of
forgotten some of the properties. Here is a code sample using a collection
object and the error I am getting when I try to perform a particular
operation: I am basically assigning values to the given Integer vars below
and then storing these vars (or their values) in the collection object col.
Then I want to change the value of one of the collection items but I get an
error -- as depicted beolw. Is there a way to get around this? Or should I
create class objects with properties instead and create my own collection
class?

Dim col As New Collection
Dim i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer
i1 = 10
i2 = 20
i3 = 30
i4 = 40

col.Add i1, "1"
col.Add i2, "2"
col.Add i3, "3"
col.Add i4, "4"

col("1") = 15 <--try to change value of this col itme - error here "object
required"