What is the difference between a class module and a module.
When should i use a Class module instead of module??
Thanx for the help
Printable View
What is the difference between a class module and a module.
When should i use a Class module instead of module??
Thanx for the help
A module is a block of code. You use modules to keep code pieces in manageable, comprehensible pieces.
Class modules or libraries are special pieces of compiled code (.DLL or ActiveX .EXE files) that follow COM rules. They are registered, and in the registry hive HKEY_CLASSES_ROOT there will be a unique (GUID) 128-bit identifier for classes associated with the .DLL or ActiveX .EXE file.
You use the Class libraries or Class modules in your code as objects. You can create your own objects by having a .CLS module that is part of your VB project. No other project can use this .CLS file, it's private to the project.
A class module is used when you want to create multipul instances of the variables and functions within.
A Module can only be used once
E.g. In a helpdesk system a module may have a global database defined in it, and functions called ConnectDatabases, Login, Printcall etc
A Class module may be for a call or customer as there will be multipul customers and calls, each with there own data, but which you want a set of standard fuctions for (such as createcall, findcustomer etc).
With this you could have several customers/calls loaded at once
From MS:
Class modules differ from standard modules in the way their data is stored. There's never more than one copy of a standard module’s data. This means that when one part of your program changes a public variable in a standard module, and another part of your program subsequently reads that variable, it will get the same value. Class module data, on the other hand, exists separately for each instance of the class (that is, for each object created from the class). By the same token, data in a standard module has program scope — that is, it exists for the life of your program — while class module data for each instance of a class exists only for the lifetime of the object; it’s created when the object is created, and destroyed when the object is destroyed.
Finally, variables declared Public in a standard module are visible from anywhere in your project, whereas Public variables in a class module can only be accessed if you have an object variable containing a reference to a particular instance of a class. All of the above are also true for public procedures in standard modules and class modules