Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1071935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:46:52+00:00 2026-05-16T20:46:52+00:00

For example I have class A which implements class B —class A—- implements B

  • 0

For example I have class A which implements class B

—class A—-

implements B
public sub B_do()
end sub

–class B—-

public sub do()
end sub

How can I call do() from A? (super.do()) So, how I can define some common variable for both classes? Now I can inherit only functions, sub and properties…

added: same question http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/5a83d794-3da1-466a-83d3-5d2eb0a054b2

added: It is not possible to share variable across hierarhy of classes. You should implements property (same way as functions).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:46:52+00:00Added an answer on May 16, 2026 at 8:46 pm

    The usual way to do this in VBA is to have A contain an instance of B as well as having A implement B’s interface, and then delegate calls to the B interface of A to the internal B.

    This is old stuff, but see the Visual Studio 6.0 Programmer’s Guide:

    http://msdn.microsoft.com/en-us/library/aa716285(VS.60).aspx

    There is a chapter on “The Many (Inter)Faces of Code Reuse” that describes this convention:

    http://msdn.microsoft.com/en-us/library/aa240846(v=VS.60).aspx

    The way MS describes it is:

    In addition to implementing abstract
    interfaces, you can reuse your code by
    implementing the interface of an
    ordinary class, and then selectively
    delegating to a hidden instance of the
    class.

    This means that implementation inheritance requires lots of explicit delegation methods. There’s even a chapter subheading: “Doesn’t This Get Tedious?”. Yet another reason why OOP in VBA is a PITA (TM)…

    EDIT THAT WON’T FIT IN A COMMENT:

    To answer the question you posed in your comment, well, an A is a B. When you make A implement B’s interface, you are essentially saying that you can treat an instance of A as if it is actually of type B. In VBA, the way you do that is by declaring a variable of type B, and then setting it to an instance of A. VBA will know what to do when you call it like a B:

    Dim usedAsB as B
    Dim anA as A
    
    Set anA = New A
    Set usedAsB = anA    'fine since A implements B
    
    usedAsB.something()    'will call B_something() defined in class A
    

    As far as what you see in the debug window, I don’t why it appears that way. And as far as forced delegation, I’m not sure what you mean. VBA automatically dispatches calls to the B interface to the right methods in the A class. If you mean automatically generating the code to inherit B’s implementation in the manner described above, there’s nothing like that I know of for VBA. I think the various “professional” versions of VB6 could do that, but I’ve never used VB6 so I don’t know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example I have a simple class like public class Person{ public int Age
For example, suppose I have a class: class Foo { public: std::string& Name() {
I used to have one class for one file. For example car.cs has the
Consider this example (typical in OOP books): I have an Animal class, where each
I am using a fictional example for this. Say, I have a Widget class
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
I have the following example code: class A(object): def __init__(self, id): self.myid = id
I have a unit test (example is modified Test::Unit documentation ) require 'test/unit' class
If I have a class as follows class Example_Class { private: int x; int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.