VBA does not see public class variables in COM addin

N

Nick Dreyer

Is it possible to see public class variables of a COM addin in Excel 97 VBA?

I have successfully created the (Visual Basic 2003 .NET) COM
and referenced it in an Excel 97 VBA project. The VBA object browser sees -
and the project otherwise successfully interacts with - all the COM addin
methods and properties, but none of the public variables - target, init and
size in the code below - can be accessed. When I reference the exact same COM
from another dotnet project, the COM class public variables are all available.

What is going on here?

I notice that I have to choose the COM addin's .tlb file, not the .dll file in
the VBA reference dialog box. Is that expected?

Can Excel 97 VBA just not access COM class variables - or "fields" as the
dotnet documentation calls them? If so, that is going to be a serious
limitation for me.

The vb.net code of the COM addin I am using is like this:

<ComClass(fpm_goalseek_class.ClassId, _
fpm_goalseek_class.EventsId, _
fpm_goalseek_class.InterfaceId)> _
Public Class fpm_goalseek_class

Public Const ClassId As String = "6C1967B7-4EC8-4b70-BA94-C131EE892452"
Public Const InterfaceId As String = "4CDC9471-D4E2-4824-BD4D-938EF299D58C"
Public Const EventsId As String = "4D18D7F1-BC51-49f0-824B-69F607EBD3B2"

Public target as double
Public init as double
Public size as double

' . . . Body of class code here . . .

End Class


|\|.
 
K

Ken Tucker [MVP]

Hi,

I would expose a public property instead of a public variable.

Ken
--------------
Is it possible to see public class variables of a COM addin in Excel 97 VBA?

I have successfully created the (Visual Basic 2003 .NET) COM
and referenced it in an Excel 97 VBA project. The VBA object browser sees -
and the project otherwise successfully interacts with - all the COM addin
methods and properties, but none of the public variables - target, init and
size in the code below - can be accessed. When I reference the exact same
COM
from another dotnet project, the COM class public variables are all
available.

What is going on here?

I notice that I have to choose the COM addin's .tlb file, not the .dll file
in
the VBA reference dialog box. Is that expected?

Can Excel 97 VBA just not access COM class variables - or "fields" as the
dotnet documentation calls them? If so, that is going to be a serious
limitation for me.

The vb.net code of the COM addin I am using is like this:

<ComClass(fpm_goalseek_class.ClassId, _
fpm_goalseek_class.EventsId, _
fpm_goalseek_class.InterfaceId)> _
Public Class fpm_goalseek_class

Public Const ClassId As String = "6C1967B7-4EC8-4b70-BA94-C131EE892452"
Public Const InterfaceId As String =
"4CDC9471-D4E2-4824-BD4D-938EF299D58C"
Public Const EventsId As String = "4D18D7F1-BC51-49f0-824B-69F607EBD3B2"

Public target as double
Public init as double
Public size as double

' . . . Body of class code here . . .

End Class


|\|.
 
N

Nick Dreyer

Thanks for the thought, however . . .

I am quite aware that properties are substitutes for exposed class variables.

I just don't know what the point of going through all the trouble of setting
up property let/set code for every single variable that needs to be accessed
outside the VB.NET class.

Are you telling me that there is no way of exposing public class variables in
VB.NET COM builds? If so what's the point of the "public" qualifier for class
variables in VB.NET?

VB.NET makes public variables visible to other VB.NET projects, why won't COM?

I appreciate any more insights into this matter, if only in the form (or
reference to source) of a good explanation as to why exposing public variables
is not worthy of support in COM.

Thanks in advance, |\|.
 
A

Armin Zingler

Nick said:
Thanks for the thought, however . . .

I am quite aware that properties are substitutes for exposed class variables.

I just don't know what the point of going through all the trouble of setting
up property let/set code for every single variable that needs to be accessed
outside the VB.NET class.

Are you telling me that there is no way of exposing public class variables in
VB.NET COM builds? If so what's the point of the "public" qualifier for class
variables in VB.NET?

VB.NET makes public variables visible to other VB.NET projects, why won't COM?

AFAIR, COM itself does not support public 'variables', only public methods.
If you write a COM class in VB6, public variables are also implemented as
property procedures internally.


Armin
 
N

Nick Dreyer

AFAIR, COM itself does not support public 'variables', only public methods.
If you write a COM class in VB6, public variables are also implemented as
property procedures internally.


Armin

So I take it VB.NET does not do this. It sure would be nice if it did. A bit
of a downgrade from VB6, I'd say.

|\|.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top