Class Initialize


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Class Initialize

  1. #1
    Andy Miller Guest

    Class Initialize


    In VB, can you over-ride the default initialize procedure? I know you can
    do it in C++, but I can't quite get it to work with VB. Here's what I'm
    trying to do:
    Let's say I have a class called Cube... I want to be able to say something
    like "Set X = New Cube(3)" to indicate a 3x3x3 cube. Then, in the initialize
    procedure of the class, I would dimension the arrays accordingly. I know
    that the cube example isn't a very good one, but I think it illustrates my
    point.

    TIA,

    Mill

  2. #2
    Colin McGuigan Guest

    Re: Class Initialize

    Andy Miller wrote in message <38dfaf86$1@news.devx.com>...
    >
    >In VB, can you over-ride the default initialize procedure? I know you can
    >do it in C++, but I can't quite get it to work with VB. Here's what I'm
    >trying to do:
    >Let's say I have a class called Cube... I want to be able to say something
    >like "Set X = New Cube(3)" to indicate a 3x3x3 cube. Then, in the

    initialize
    >procedure of the class, I would dimension the arrays accordingly. I know
    >that the cube example isn't a very good one, but I think it illustrates my
    >point.
    >
    >TIA,
    >
    >Mill


    No, although Microsoft has promised this in VB7. The best alternative is to
    simply have some proc (Initialize or similar) that must be called. An
    alternative is to wrap this within a function, so you might have:

    Public Function CreateCube(lngLength As Long) As CCube
    Dim clsCube As CCube

    Set clsCube = New CCube
    clsCube.Initialize lngLength
    Set CreateCube = clsCube
    End Function

    --
    Colin McGuigan




  3. #3
    Craig Clearman Guest

    Re: Class Initialize

    Andy,

    >In VB, can you over-ride the default initialize procedure?


    Not until VB7.

    Until then, you have two options. First, you can add Init methods to
    your classes:

    Set x = New Cube
    Call x.Init(3)

    Or you can create accessor functions that do the same work for you.

    Ciao, Craig


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center