Results 1 to 2 of 2

Thread: [02/03] passing a collection to a constructor

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    18

    [02/03] passing a collection to a constructor

    Hi...does anyone know to pass a controls collection to a constructor?
    It is only supposed to have 1 argument.
    There are 5 methods ont he form (4 are the lst box collections and 1 is the
    total of all. I'm guessing that is the one to send, but am unsure how to do)
    It also wants this MyBase.New statement????
    Any thoughts are greatly appreciated.
    Attached Files Attached Files

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] passing a collection to a constructor

    Please post the relevant section of code directly as many people, myself included, are unlikely to want to download entire projects unnecessarily.

    Having said that, a constructor is just a method. If you want to pass parameters to a constructor then you have to declare an argument list, just like any other method, e.g.
    VB Code:
    1. Public Sub New(ByVal controls As ControlCollection)
    When you invoke the instructor, which you do with the "New" key word, you pass the parameter value just like you do any other method, e.g.
    VB Code:
    1. Dim f2 As New Form2(Me.Controls)
    I'm quite sure that you've passed parameter values to other constructors before.

    As for MyBase.New, MyBase always refers to the base class of the current instance. By calling MyBase.New in your constructor you are calling the base class's constructor first, which does all the standard work of constructing the object before you add code to perform the custom work specific to your class.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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