Connecting Tech Pros Worldwide Forums | Help | Site Map

VBA does not see public class variables in COM addin

Nick Dreyer
Guest
 
Posts: n/a
#1: Nov 21 '05
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


|\|.

Ken Tucker [MVP]
Guest
 
Posts: n/a
#2: Nov 21 '05

re: VBA does not see public class variables in COM addin


Hi,

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

Ken
--------------
"Nick Dreyer" <gurfle@oz.net> wrote in message
news:42d26131.4716249@news.oz.net...
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


|\|.


Nick Dreyer
Guest
 
Posts: n/a
#3: Nov 21 '05

re: VBA does not see public class variables in COM addin


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, |\|.

On Sat, 9 Jul 2005 06:30:20 -0400, "Ken Tucker [MVP]" <vb2ae@bellsouth.net>
wroth:
[color=blue]
>Hi,
>
> I would expose a public property instead of a public variable.
>
>Ken
>--------------
>"Nick Dreyer" <gurfle@oz.net> wrote in message
>news:42d26131.4716249@news.oz.net...
>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
>
>
>|\|.
>
>[/color]

Armin Zingler
Guest
 
Posts: n/a
#4: Nov 21 '05

re: VBA does not see public class variables in COM addin


Nick Dreyer schrieb:[color=blue]
> 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?[/color]

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
Nick Dreyer
Guest
 
Posts: n/a
#5: Nov 21 '05

re: VBA does not see public class variables in COM addin


On Sat, 09 Jul 2005 19:59:22 +0200, Armin Zingler <az.nospam@freenet.de>
wroth:
[color=blue]
>Nick Dreyer schrieb:[color=green]
>>
>> VB.NET makes public variables visible to other VB.NET projects, why won't COM?[/color]
>
>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[/color]

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.

|\|.
Closed Thread