Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference Between A Module & A Class

Status
Not open for further replies.

RebelFox

Programmer
Jun 16, 2002
62
GB
Can somebody explain to me the difference between a class and a module in a VB project?
 
I'm not very informed about classes at all, but I think that a class is sort of like a specialized group of code. For forms, buttons, textboxes...I think...are all basically classes.

Modules are, for me, just ways to break up code in more managable sections. For instance, I might have a module that just dealt with updates, and another that dealt with adds. It could all be in the same module, but breaking it up makes it easier to follow.

Though I, too, would like to hear what others have to say.
 
I believe that Classes are objects where the code is self contained. They usually do a specific job well and are designed to be easily reused without changing the code. The object needs to be properly created and qualified when used.

A module is a way to share variables, functions and procedures throughout an application. A way to use global scope.

Take Care,

zemp

"Show me someone with both feet on the ground and I will show you someone who can't put their pants on."
 
A class is the core of Object Oriented Programming. They are very similiar to a Structure in C++ programming.

A module will contain variables, functions as well as classes.
 
>>They are very similiar to a Structure in C++ programming.

No they are not. Apart from the fact that they can contain public and private vars and methods and can be instantiated multiple times, they're far from what a C++ Class or Struct can do. And they also have something a C++ Class or Struct cannot do: they can generate events.

Actually the difference is very simple:
A class is some encapsulated piece of code, as well as a module can be. Both can contain private- as well as public vars and methods.

However, a module can be accesed without having to instiate it, it's always there; no matter in which part of your app you are; you can always access it's vars and methods (provided that they're public, of course.....).
A class needs to be instantiated first. You cannot use anything unless you have created an instance of it.
And this leads to the main difference of them (apart from classes having constructors/destructors and being able to generate events): There's never no more than ONE "instance" of your module; only one instance of its vars. Whereas you can have as many instances of a particular class as you wish; so as many instances as its vars as well....

Greetings,
Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top