473,479 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is there an easy way to expose class variables in COM builds?

In VB.NET I would like to not have to create property get/set procedures for
every class variable I want to expose to Excel VBA projects in COM builds.

Can anyone tell me if that is possible, or refer me to some documents that
will make me understand why this apparent limitation of VB.NET COM builds is
acceptable, i.e. why in "good" object code programs I should expect to never
have to create large numbers of public class variables that need to be visible
outside of objects?

I gather that this was not an issue in VB6, so why the limitation in VB.NET?
|\|.
Nov 21 '05 #1
6 1036
> why in "good" object code programs I should expect to never
have to create large numbers of public class variables that need to be visible
outside of objects?
I don't think there is any design pattern that recommends against the above. Shouldn't it just depend upon the needs of your app?

I've never heard of that "limitation" and so am curious as to the source of the information.

If you really want to avoid making properties, you can just use public fields. Really, your choices are methods or fields since
properties become methods when compiled.
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Nick Dreyer" <gu****@oz.net> wrote in message news:42*************@news.oz.net... In VB.NET I would like to not have to create property get/set procedures for
every class variable I want to expose to Excel VBA projects in COM builds.

Can anyone tell me if that is possible, or refer me to some documents that
will make me understand why this apparent limitation of VB.NET COM builds is
acceptable, i.e. why in "good" object code programs I should expect to never
have to create large numbers of public class variables that need to be visible
outside of objects?

I gather that this was not an issue in VB6, so why the limitation in VB.NET?
|\|.

Nov 21 '05 #2
"Nick Dreyer" <gu****@oz.net> schrieb:
In VB.NET I would like to not have to create property get/set procedures
for
every class variable I want to expose to Excel VBA projects in COM builds.

Can anyone tell me if that is possible, or refer me to some documents that
will make me understand why this apparent limitation of VB.NET COM builds
is
acceptable, i.e. why in "good" object code programs I should expect to
never
have to create large numbers of public class variables that need to be
visible
outside of objects?

I gather that this was not an issue in VB6, so why the limitation in
VB.NET?

In VB6 public variables were compiled to properties. I suggest to use
properties in your VB.NET project instead of public variables if you want
them to be exposed to COM.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

"Nick Dreyer" <gu****@oz.net> wrote in message
news:42*************@news.oz.net...
In VB.NET I would like to not have to create property get/set procedures for every class variable I want to expose to Excel VBA projects in COM builds.

Can anyone tell me if that is possible, or refer me to some documents that
will make me understand why this apparent limitation of VB.NET COM builds is acceptable, i.e. why in "good" object code programs I should expect to never have to create large numbers of public class variables that need to be visible outside of objects?

I gather that this was not an issue in VB6, so why the limitation in VB.NET?


VB6 was COM based. There was much plumbing that it performed for you in the
background. It would automatically create the Interfaces, Type Libraries,
and many other things. With public variables / fields, VB6 would
automatically turn these into properties/methods for you. It is a
requirement of COM that anything being exposed externally have an entry for
the Interface in the Type Library. VB6 was also sort of an oddity in this
sense. Most other languages do not provide such things automatically. I'm
glad it did, but most others did not.

As you have found, VB.NET is not COM based. In fact, Microsoft's desire is
for .NET to replace COM whenever possible. Truth is that they really don't
want you using COM, but they realized the need for some outgoing COM
support. If you wish to provide COM support via VB.NET, you have little
choice but to dig in and learn the ins and outs of COM and implement this
all manually, much like C++ programmers have always had to do. Since
Microsoft doesn't really want this to become a common practice, they don't
make it easy. Additionally, since .NET is not COM based, it supports tons of
things that COM and therefore VB6 does not. Not automatically exposing such
things brings VB.NET inline with most other programming languages.

Gerald
Nov 21 '05 #4
Gerald:

Thanks for your insights. I have inserted a few comments/questions into the
excerpted relevant parts of your message below

On Tue, 12 Jul 2005 08:44:12 -0600, "Gerald Hernandez"
<Cablewizard@sp*********@Yahoo.com> wroth:
. . . It is a
requirement of COM that anything being exposed externally have an entry for
the Interface in the Type Library. VB6 was also sort of an oddity in this
sense. Most other languages do not provide such things automatically. I'm
glad it did, but most others did not.
So, was making it look like VB6 public class variables were exposed in COM -
by converting them to properties - one such nice "oddity"?
. . . Additionally, since .NET is not COM based, it supports tons of
things that COM and therefore VB6 does not. Not automatically exposing such
things brings VB.NET inline with most other programming languages.


To get this straight and once-and-for-all fully confirmed in my mind: VB.NET
COM builds do not convert public class variables into properties the way VB6
did? In other words I am going to have to create the property "overhead" code
myself for each such variable I need?

Lastly, is there some good reading out there on how to get one's mind thinking
about programing in a way that one's software designs minimize the use of
public class variables?

Thanks, Nick

|\|.
Nov 21 '05 #5
Nick, comments inline...

"Nick Dreyer" <gu****@oz.net> wrote in message
news:42**************@news.oz.net...
Gerald:

Thanks for your insights. I have inserted a few comments/questions into the excerpted relevant parts of your message below

On Tue, 12 Jul 2005 08:44:12 -0600, "Gerald Hernandez"
<Cablewizard@sp*********@Yahoo.com> wroth:
. . . It is a
requirement of COM that anything being exposed externally have an entry forthe Interface in the Type Library. VB6 was also sort of an oddity in this
sense. Most other languages do not provide such things automatically. I'm
glad it did, but most others did not.
So, was making it look like VB6 public class variables were exposed in

COM - by converting them to properties - one such nice "oddity"?
[GH] Yes. This was one of those nice oddities. In essence, VB6 would
automatically compile public fields as properties so they would be usable.
Interestingly, in COM the properties actually get converted to subs and
functions when compiled. So VB6 actually took a couple extra steps. In other
languages, you would have to code each get and set method as seperate subs
and functions. Ah, VB6 seemed so nice.
. . . Additionally, since .NET is not COM based, it supports tons of
things that COM and therefore VB6 does not. Not automatically exposing suchthings brings VB.NET inline with most other programming languages.


To get this straight and once-and-for-all fully confirmed in my mind:

VB.NET COM builds do not convert public class variables into properties the way VB6 did? In other words I am going to have to create the property "overhead" code myself for each such variable I need?
[GH] To the best of my knowledge, you are correct. VB.NET will not
automatically convert these variables to properties, and yes you will need
to code the wrappers / overhead yourself. However, some good news. In my
experience, I have found that creating properties in VB.NET in actually much
faster and easier than VB6. Mainly due to the autocomplete and the combined
Get/Set blocks. So while there might be more words in your source, you
actually end up doing like less than half the typing you would in VB6.

Lastly, is there some good reading out there on how to get one's mind thinking about programing in a way that one's software designs minimize the use of
public class variables?


[GH] Good question. Sadly, I don't personally know of any; hopefully someone
else will chime in with a recommendation. I get the impression that you are
thinking that we all are saying that lots of public fields in classes is a
bad thing. Well, public "variables" / "fields" exposed in the way you are
talking about is less than ideal, even in VB6 they really should be wrapped
in a property for a few very reasonable reasons. However, using classes to
store a bunch of related values, similar to a User Defined Type, is actually
encouraged, especially in .NET. If you can group related methods and make
the class more self contained / self aware, then you are on your way to the
Object Oriented approach.

[GH] Based on my experience in retraining on VB.NET from VB6, my best advice
for the moment would be: "Try" not to become too frustrated. I know it isn't
easy ;-) But take the time to learn the VB.NET way of doing things. In time,
you will adjust and it won't take too long before you start to like .NET
more than VB6. If you let the inevitable frustration take over, it will
cloud your mind to learning new things. Just keep in mind that they are
different. If you try to make VB.NET be VB6, you will drive yourself nuts.
For me personally, I don't like VB.NET's level of COM support. So what I
have been doing is coding the COM portions in VB6 still, especially for VBA,
and then referencing it into .NET. Backwards? well yeah a bit. But
interestingly, coding in VB.NET for a short time has made me a much better
VB6 programmer than decades of experience. So hang in there, it gets better.

Gerald
Nov 21 '05 #6
Thanks Gerald. I had more or less come to similar conclusions, not only about
the reality of, but also the "philosophical approach" to take with VB.NET.

Now that I have read your very considered response, I feel a lot better about
diving in to the new .NET way. There is obviously a lot to learn, and with
your assurance that there is a worthwhile outcome to look forward to, it feels
like the kind of learning that keeps drudgery from setting in - a good thing.

All the best, |\|.

On Wed, 13 Jul 2005 09:14:35 -0600, "Gerald Hernandez"
<Cablewizard@sp*********@Yahoo.com> wroth:
Nick, comments inline...

"Nick Dreyer" <gu****@oz.net> wrote in message
news:42**************@news.oz.net...
Gerald:

Thanks for your insights. I have inserted a few comments/questions intothe
excerpted relevant parts of your message below

< . . . >

So, was making it look like VB6 public class variables were exposed in

COM -
by converting them to properties - one such nice "oddity"?


[GH] Yes. This was one of those nice oddities. In essence, VB6 would
automatically compile public fields as properties so they would be usable.
Interestingly, in COM the properties actually get converted to subs and
functions when compiled. So VB6 actually took a couple extra steps. In other
languages, you would have to code each get and set method as seperate subs
and functions. Ah, VB6 seemed so nice.


< . . . >

[GH] To the best of my knowledge, you are correct. VB.NET will not
automatically convert these variables to properties, and yes you will need
to code the wrappers / overhead yourself. However, some good news. In my
experience, I have found that creating properties in VB.NET in actually much
faster and easier than VB6. Mainly due to the autocomplete and the combined
Get/Set blocks. So while there might be more words in your source, you
actually end up doing like less than half the typing you would in VB6.

Lastly, is there some good reading out there on how to get one's mind

thinking
about programing in a way that one's software designs minimize the use of
public class variables?


[GH] Good question. Sadly, I don't personally know of any; hopefully someone
else will chime in with a recommendation. I get the impression that you are
thinking that we all are saying that lots of public fields in classes is a
bad thing. Well, public "variables" / "fields" exposed in the way you are
talking about is less than ideal, even in VB6 they really should be wrapped
in a property for a few very reasonable reasons. However, using classes to
store a bunch of related values, similar to a User Defined Type, is actually
encouraged, especially in .NET. If you can group related methods and make
the class more self contained / self aware, then you are on your way to the
Object Oriented approach.

[GH] Based on my experience in retraining on VB.NET from VB6, my best advice
for the moment would be: "Try" not to become too frustrated. I know it isn't
easy ;-) But take the time to learn the VB.NET way of doing things. In time,
you will adjust and it won't take too long before you start to like .NET
more than VB6. If you let the inevitable frustration take over, it will
cloud your mind to learning new things. Just keep in mind that they are
different. If you try to make VB.NET be VB6, you will drive yourself nuts.
For me personally, I don't like VB.NET's level of COM support. So what I
have been doing is coding the COM portions in VB6 still, especially for VBA,
and then referencing it into .NET. Backwards? well yeah a bit. But
interestingly, coding in VB.NET for a short time has made me a much better
VB6 programmer than decades of experience. So hang in there, it gets better.

Gerald


Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
312
by: Nick Dreyer | last post by:
In VB.NET I would like to not have to create property get/set procedures for every class variable I want to expose to Excel VBA projects in COM builds. Can anyone tell me if that is possible, or...
3
9219
by: Oliver Bryant | last post by:
I just finished developing a javascipt component allowing floating captions to appear over HTML elements. If anyone wants to check it out you can see specs and download it from...
1
1998
by: Prigozhin Roman | last post by:
Hi , I have a COM object implemented in C# Problem is that my properties ( which defined public in the class ) can not be seen from the outside ( When I call COM ) I can see only functions I...
4
3964
by: Don | last post by:
It is possible to expose an enumerated type from within a class library so that other projects referencing that class library will see it in the class's namespace? For example, if I have a class...
4
2464
by: Nick Dreyer | last post by:
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...
3
6288
by: Miguel Ferreira via .NET 247 | last post by:
Hi ! I have developed a class Library with several classes and methods. Its working fine with a windows forms test application, but now i need to create a webservice that will expose those...
14
5399
by: Jamey Shuemaker | last post by:
Greetings all, I've been reading for the last couple hours posts on this site and various MS sites about reference libraries and class modules. System: Windows 2K running an A2K db with...
2
2160
by: GoCoogs | last post by:
I'm trying to count how many items are in a dynamic collection. This is the code I have so far. *** Begin Code *** Public Class Rule Private _rulevars As RuleVarsCollection Private _rulename...
15
2521
by: =?Utf-8?B?UGF0Qg==?= | last post by:
Just starting to move to ASP.NET 2.0 and having trouble with the Global.asax code file. In 1.1 I could have a code behind file for the global.asax file. This allow for shared variables of the...
2
1345
by: Andy B | last post by:
I need to make a class and not quite sure how to go about doing this part. I want the class to take user input, build a dataset based on that input and then return it from the class so it can be...
0
7019
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,...
0
7067
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...
1
6719
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...
0
6847
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...
1
4757
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...
0
4463
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...
0
2980
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...
0
2970
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.