Module vs Class Module

B

Brad Parks

Are there any performance or memory-usage benefits of placing public
functions and subroutines in a Class Module rather than a standard
module?
 
W

William Ryan [eMVP]

All a module is is a sealed class with all shared properties/methods etc.
I'm not sure if you are referring to 'Class Module' as in the old VBA sense
or as a Class. There is not Class Module in the VBA sense equvialent in
..NET
 
A

Armin Zingler

Brad Parks said:
Are there any performance or memory-usage benefits of placing
public functions and subroutines in a Class Module rather than a
standard module?

No. A Module *is* a special class:
- all members are automatically declared Shared
- no instance can be created
- it is imported automatically at project level
 
H

Herfried K. Wagner [MVP]

Brad,

* (e-mail address removed) (Brad Parks) scripsit:
Are there any performance or memory-usage benefits of placing public
functions and subroutines in a Class Module rather than a standard
module?

If you are referring to VB Classic (Version 1-6), please turn to one of
the microsoft.public.vb.* groups.

For VB.NET: Modules get compiled to friend classes which are imported
automatically. There are no performance and memory-using benefits when
using a class with shared methods instead.
 
J

Jay B. Harlow [MVP - Outlook]

Brad,
If by "Class Module" you are referring to a class that only has Shared
members, then as the others have stated there is no performance or
memory-usage benefits.

However! the biggest benefit I see to using classes with Shared members over
Modules is encapsulation, you are "required" to qualify the name of the
class when you use one of the shared members, ensuring that you know were
that member is coming form.

BTW: You can relax this "requirement" by importing the class itself, which
then allows it to work like a Module for that source file.

For example:
Imports System.Math

Hope this helps
Jay
 

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