473,811 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherited interface not seen by VBA client

1 New Member
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 876

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

Similar topics

4
1583
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. IMO explaining how to put majordomo.listers.isp.com in the to: line and "subscribe listname" for these people is error prone. Is there some generic code that fires up the default mail application and stuff this information into it. Asking the...
6
389
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 similar to what I'm thinking about. Lets suppose I make a class called RoleCollection.
2
412
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 great, I've run into a problem. Say intefaceA derives from interfaceB and so gets interfaceB's members: public interfaceA : intefaceB
5
1682
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 something about dll's an using Visual studio.net in another post, I prefer vb.net or c# cos I am familiar with vb an c# is supposed to be easier than c++ which was somewhat painful :)
6
5199
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 properties defined in the inherited interface. However when playing with this and defining a class to implement the interface the class gets implemented with both sets of interface declarations. eg.
2
1577
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 some of the questions are not in the usual multiple-choice format. I have some illustrations below: 1) the drag-n-drop of textboxes from one panel onto another panel. Is this possible in asp.net ? 2) another question require that the user place...
7
2422
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
1302
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. I'm declaring an event in a interface. I'm consuming the interface via another inherited Interface. I'd like to have my classes respond to this 'one' event... Based on my below example code, I'd like both Classes Test1 and Test2 to
0
1018
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 based interface from client machine theBond
0
1222
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 properties declared in the inherited interface, and ignores the properties declared in a basic interface. I found some solution, that I should write my own TypeConverter for my interface and override GetProperties method, but I couldn't find the way...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.