adding to a collection class without .add
I'd like to implement an interface like the one in the ADO command / parameter object so i can use syntax like:
mQry.add(0) = "value" rather than having to explicitly use (for example) : mQry.Paramters.add "value"
I'm using a collection class to do it at the moment and know i need to use add within the class but at the moment i can't pick up the value as it seems way out of scope.
Any ideas / code welcome.
Re: adding to a collection class without .add
Hi
Here's an example. You use a 'Property Let Add' on the collection class
In your collection class :
Option Explicit
Private mCol As Collection
Public Property Let Add(ByVal sKey As String, ByVal sName As String)
On Error GoTo vbErrorHandler
mCol.Add sName, sKey
Exit Property
vbErrorHandler:
Err.Raise Err.Number, Err.Source, Err.Description
End Property
When called from a VB routine :
mCollection.Add(2) = "Whatever"
mCollection.Add("Thing") = "Another thing"
You'll obviously have to add better error checking/handling.
Regards
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb