CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Constructor in Visual Basic ?

  1. #1
    Join Date
    Jan 2003
    Location
    Bangalore, INDIA
    Posts
    180

    Constructor in Visual Basic ?

    Hi Guys

    How do we write a Constructor in Visual Basic ?
    Somebody please help.

    Thanks

    Suhaib

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    I don't think so..
    Busy

  3. #3
    Join Date
    Apr 2002
    Posts
    388
    Create a class module.

    There you could use the class_initialize for the constructor and class_terminate as destructor.

    The only (big) problem is, that you are not able to pass parameters to the constructor to initialize members. If you want to do so you should write your own Initialize method and call this method in every instance of the class.
    mfg Ungi

    Music, music and VB. VB is like music: You never know how it is interpreted.

  4. #4
    Join Date
    Jan 2003
    Location
    Bangalore, INDIA
    Posts
    180
    Thanks a ton Ungi !!

  5. #5
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Yeah, that's the default constructor but you couldn't write your own constructor in VB..
    Busy

  6. #6
    Join Date
    Apr 2002
    Posts
    388
    Originally posted by Thread1
    Yeah, that's the default constructor but you couldn't write your own constructor in VB..
    Yes you are right, the initialize and terminate are not real construktors, but class modules are also not really object oriented. (And the old discussion restarts...)

    But initialize is called when an object is instanced and terminate when all references to the object are released. So they have very simmilar to constructor and destructor, aren't they.
    mfg Ungi

    Music, music and VB. VB is like music: You never know how it is interpreted.

  7. #7
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Yeah sure they act like almost the same as the constructor and destructor in OOP.. But still you can't write your own in VB..
    Busy

  8. #8
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    True, you can not...

    ..you can only add a method, if you need parameters on starting up, to be called as first. But it is not a constructor....
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)