Results 1 to 2 of 2

Thread: Polymorphism

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    7

    Question

    I have two classes called A and B. They both use a sub procedure within them called calculate_V2. Each class calculates V2 differently.
    From my form I want to call one of these sub procedures depending on the situation. So I created an interface to link the two classes called class_interface. In class A and B I wrote 'Implements class_interface' at the top.

    In the interface class I wrote
    Public Sub calculate_V2()
    End Sub

    In class A and B I wrote
    Public Sub class_interface_calculate_V2()
    'calculating code
    End Sub

    Then in the form, I created a class A object, a class B object and class_interface object. I make class_interface equal class A or B depending on the situation. So when I have 'class_interface.calculate_V2' it calls the associated sub procedure.
    Example:
    Set class_interface = class A
    class_interface.calculate_V2
    'This calls calculate_V2 from class A

    Set class_interface = class B
    class_interface.calculate_V2
    'This calls calculate_V2 from class B

    This all works fine, sorry for blabbing on!

    The problem is class A and B both have the property V2
    I want to retrieve this property from either class by using the class_interface.
    So in class_interface

    Public Property Get V2() as Double
    End Sub

    In Class A and B
    Public Property Get class_interface_V2() as Double
    class_interface_V2 = mvarV2
    End Sub

    So now I want to be able to do this:
    Set class_interface = class A
    variable = class_interface.V2
    'Get the V2 property from class A

    Set class_interface = class B
    variable = class_interface.V2
    'Get the V2 property from class B

    But when I run the project I get this error:
    Object module needs to implement 'class_interface_V2' for 'class_interface'.
    But I think I have already done this!

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    I may be mistaken but I do not believe polymorphism and inheritance, which is what your are attempting to do, can not be done yet in vb.

    It will be available in visual basic 7 which is scheduled to release first quarter 2001.

    Check on microsoft's site, and some other developers and you will find articles talking of how vb 7 will include inheritance...

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