PDA

View Full Version : Sleeper: Collection Class - Item Method



clew
06-18-2010, 12:54 PM
Hello. I'm new to working with custom collection classes, etc. I have successfully created a few custom classes and collection classes. I am noticing something that does not seem to make sense though.

For one collection class, I have created a method that returns an object in the collection with the given index. It works like the Item method of the normal vb Collection object.


Function IMS(Index As Variant) As CIMS
Set IMS = System_Collection.Item(Index)
End Function
Once I've added IMS objects to the System, I can call them using


System.IMS(i)
where i is the index. So far, so good.

The problem I have is that I want to use a selection from a listbox to determine the index of the IMS to be called. The listbox is populate with numbers (1, 2, 3...), so I should be able to use:


Sheets(1).ListBox1.value
as the argument of the IMS method from above. But for some reason, I get an error every time I try that. 'Invalid procedure call or argument'. I don't understand why that happens. The Index argument is a variant, so shouldn't this work? I checked that the listbox value is numeric. And I know the index number is valid. My work-around is that I declare an integer, store the listbox value to it and use that variable as the Index. This makes no sense to me.

Any thoughts? Sorry for the long post. Thanks in advance.

Bob Phillips
06-18-2010, 04:03 PM
Perhaps it is because the listbox value returns a variant string?