
What is diff. class Class Module & Module
No problem :)
Class modules are designed for code reuse, so that code does not have to be
replicated. Its like having a user defined type which can perform functions
without any extra programming.
Once you have programmed them once you can create "instances" of them in
your main code, which you then manipulate like an object. Another big
advantage is that you can load them into arrays, which is dead handy when
you want to have lots of identical objects.
If you have ever used the FileSystemObject, that is a good example of a
class module (made by Microsoft though)
Creating a class module is simple - just add public subs/functions to it for
subs/functions that you want the user to know about, and add private
subs/functions for ones which are called from within your code. You can also
add properties, like in user controls, which expose private variables to the
main program.
To use a class module, first dim a variable as the module:
Dim Whatever As clsWhatever
Then "set" the module:
Set Whatever = New clsWhatever
You can then manipulate the module:
Whatever.WhateverSub
Whatever.Whatever = 50
Var = Whatever.WhateverFunction
To create arrays of them, just dim the module like a normal array:
Dim Whatever() As clsWhatever or
Dim Whatever(50) As clsWhatever
And access it normally.
Class modules are great because it means you can easily reuse code, in these
little self contained units. As long as you supply some good documentation
along with it, another programmer can use it far more easily than a normal
module.
Class modules can also have events like controls. Just declare the event in
the General section of the class module:
Event Whatever(What As String, Ever As Integer)
And the raise it whenever it needs to happed:
RaiseEvent Whatever("Hi", 50)
To use a class module with events, declare it WithEvents:
Dim WithEvents Whatever As clsWhatever
And you will see its name in the left combo box on the code view.
Class modules have another advantage - they can "Implement" an interface. An
is a class module with only defentions of functions, which your class module
then programs. This is very useful in a client / server environment, but its
a bit tricky to explain. There are some good books around on COM and this
subject.
And thats all there is to it :) Whew.
Hope this was helpful!
Max Bolingbroke