Consulting

Results 1 to 2 of 2

Thread: Sleeper: Collection Class - Item Method

  1. #1
    VBAX Regular
    Joined
    Jun 2010
    Posts
    8
    Location

    Sleeper: Collection Class - Item Method

    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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Perhaps it is because the listbox value returns a variant string?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •