473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Inherited interface not seen by VBA client

I am writing a COM Add-in for Microsoft Access 2010 using Visual Basic 2010.

I do not understand why the members of an inherited interface are not available to VBA. They do not appear in the VBA Object Browser and a run-time error occurs if an attempt is made to use them.

Here is a full code sample which demonstrates the problem:

First I have a base class with a defined interface:
Expand|Select|Wrap|Line Numbers
  1. Public Interface IClassBase
  2.     Property id As String
  3.     Property Name As String
  4. End Interface
  5.  
  6. <ClassInterface(ClassInterfaceType.None)> _
  7. Public Class ClassBase
  8.     Implements IClassBase
  9.  
  10.     Private mstr_id As String
  11.     Private mstr_Name As String
  12.  
  13.     Public Property id As String Implements IClassBase.id
  14.         Get
  15.             id = mstr_id
  16.         End Get
  17.         Set(ByVal value As String)
  18.             mstr_id = value
  19.         End Set
  20.     End Property
  21.  
  22.     Public Property Name As String Implements IClassBase.Name
  23.         Get
  24.             Name = mstr_Name
  25.         End Get
  26.         Set(ByVal value As String)
  27.             mstr_Name = value
  28.         End Set
  29.     End Property
  30. End Class
  31.  
Next I inherit the base class and interface into a derived class:
Expand|Select|Wrap|Line Numbers
  1. Public Interface IClassDerived
  2.     Inherits IClassBase
  3.     Property extra As String
  4. End Interface
  5.  
  6. <ClassInterface(ClassInterfaceType.None)> _
  7. Public Class ClassDerived
  8.     Inherits ClassBase
  9.     Implements IClassDerived
  10.  
  11.     Private mstr_extra As String
  12.  
  13.     Public Property extra As String Implements IClassDerived.extra
  14.         Get
  15.             extra = mstr_extra
  16.         End Get
  17.         Set(ByVal value As String)
  18.             mstr_extra = value
  19.         End Set
  20.     End Property
  21. End Class
  22.  
This works fine within Visual Basic .NET. However in VBA, only the "extra" member of the derived class is visible. The "id" and "Name" properties are missing from the COM library interface.

The following code works around the problem. I make the members of the base class overridable:
Expand|Select|Wrap|Line Numbers
  1. Public Interface IVBAClassBase
  2.     Property id As String
  3.     Property Name As String
  4. End Interface
  5.  
  6. <ClassInterface(ClassInterfaceType.None)> _
  7. Public Class VBAClassBase
  8.     Implements IVBAClassBase
  9.  
  10.     Private mstr_id As String
  11.     Private mstr_Name As String
  12.  
  13.     Public Overridable Property id As String Implements IVBAClassBase.id
  14.         Get
  15.             id = mstr_id
  16.         End Get
  17.         Set(ByVal value As String)
  18.             mstr_id = value
  19.         End Set
  20.     End Property
  21.  
  22.     Public Overridable Property Name As String Implements IVBAClassBase.Name
  23.         Get
  24.             Name = mstr_Name
  25.         End Get
  26.         Set(ByVal value As String)
  27.             mstr_Name = value
  28.         End Set
  29.     End Property
  30. End Class
  31.  
I declare each member of the base class in the interface for the derived class and override each member of the base class:
Expand|Select|Wrap|Line Numbers
  1. Public Interface IVBAClassDerived
  2.     Property id As String
  3.     Property Name As String
  4.     Property extra As String
  5. End Interface
  6.  
  7. <ClassInterface(ClassInterfaceType.None)> _
  8. Public Class VBAClassDerived
  9.     Inherits VBAClassBase
  10.     Implements IVBAClassDerived
  11.  
  12.     Private mstr_extra As String
  13.  
  14.     Public Property extra As String Implements IVBAClassDerived.extra
  15.         Get
  16.             extra = mstr_extra
  17.         End Get
  18.         Set(ByVal value As String)
  19.             mstr_extra = value
  20.         End Set
  21.     End Property
  22.  
  23.     Public Overrides Property id As String Implements IVBAClassDerived.id
  24.         Get
  25.             id = MyBase.id
  26.         End Get
  27.         Set(ByVal value As String)
  28.             MyBase.id = value
  29.         End Set
  30.     End Property
  31.  
  32.     Public Overrides Property Name As String Implements IVBAClassDerived.Name
  33.         Get
  34.             Name = MyBase.Name
  35.         End Get
  36.         Set(ByVal value As String)
  37.             MyBase.Name = id
  38.         End Set
  39.     End Property
  40. End Class
  41.  
The problem with this method is that I have to override every member of the base class just to get them into the interface for the derived class. Since the members are mainly passive properties, I have lost most of the advantages of inheriting the base class.

Am I missing something? Why does VBA not recurse into the inherited interfaces correctly? Is there a way of telling the type library exporter to expand the inherited interfaces?
Sep 3 '10 #1
0 860

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Al Dykes | last post by:
W want to put code into an organization web site to let people signup for an email list on a majordomo list server. I'd like it to me as mindless as possible for the very non-technical audience. ...
6
by: thechaosengine | last post by:
Hi all, Is there a way to hide a member in a subclass that has been inherited from a base class? Lets leave aside any issues regarding whether its a good idea for a moment. Here's an example...
2
by: colinjack | last post by:
Hi All, Not sure if this is the correct forum for this but I cant seem to find a more specific one for NMock... I'm trying to use the dynamic mocking functionality of NMock and, whilst its...
5
by: dotun | last post by:
Hi Guys Could anyone tell me whether either, ASP, or ASP.NET/VB.net or ASP.NET/C# enable me to create a web application with no source code available to be seen by the clients people. I read...
6
by: Donal McWeeney | last post by:
I was under the impression that in an interface declaration I could inherit another interface declaration and the result would be that the inheriting interface could include the methods and...
2
by: Andrew | last post by:
Hi all, I have a question about the various types of graphical interface design that I can implement using asp.net n c# on Internet Explorer. I am writing a questionnaire, the problem is that...
7
by: p_shakil | last post by:
Hi, I would like to know the interface concept in Python.How the Interface is defined and implemented in Python?. How to access the interface fromn Client? Thanks PSB
11
by: Wayne Pedersen | last post by:
Need some help - and I may be doing this wrong, so please correct and suggest! I'm learning the MVP method, which I seem to have a good grasp of. Now I am trying something a bit more advanced. ...
0
theBond
by: theBond | last post by:
HI! I am trying to open word document on server through c# from client web interface but i am not getting success. can anyone guide me on how can i open doc file which is on server through web...
0
by: Agnieszka | last post by:
Hello, I developed two interfaces, one of them inherits from the another one. Then I wanted to set DataGridView datasource on the inherited interface - and, what a shame - it displays only the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.