• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Can I pass a property ~name~ to a subroutine?

BobBridges

Active Member
Not sure this is possible: Can I write a general subroutine that sorts a collection of objects on one of the object properties—WAIT, DON'T ANSWER YET!—where the property varies from one call to another? Like this, for example: I have two objects, Obj1 and Obj2. Obj1 has a number of properties include one called Key. Obj2 has only two properties named Name and Value. Is it possible to do this?
Code:
Set Coll1 = SortCollection(Obj1, Key)
Set Coll2 = SortCollection(Obj2, Name)
Set Coll3 = SortCollection(Obj2, Value)
The SortCollection function must sort the collection provided by the property specified in the second argument. Can it be done?
 
At first glance the answer should be yes but that needs an accurate sample project rather than a too generic …​
As in a previous thread in case of the VBA Collection object I explained I directly create the Collection sorted​
so without the need to sort it 'after' …​
 
I don't understand. The description above is all I think is needed to understand my question. If I can help by rephrasing it, what I'm wondering is this: Is there a way for a subroutine to act upon a particular property of an object—which property to be determined at execution time by information sent from the caller? In one call to the subroutine I want it to operator on property A, and in another call to the same subroutine I want it to operate, in the same way, on property B.

So far I haven't seen a way for this to happen.
 
See the VBA function CallByName …​
A post sample :​
 
Oh, COOL!!! Thank you, thank you, thank you! I needed a few hours to read, comprehend, and test, but it's beautiful! Just what I needed, though I didn't think so at first sight. Ok, I can go back to work now. Je te remercie mille fois.
 
Back
Top