CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 1999
    Posts
    1

    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.

  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    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



Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured