What is diff. class Class Module & Module 
Author Message
 What is diff. class Class Module & Module

What is diff. class Class Module & Module


Sun, 20 Jun 2004 22:32:38 GMT  
 What is diff. class Class Module & Module
Hi,

Actually this is newsgroup which discusses ADO, not
general VB questions. But in general Module is a container
for procedures, functions and variables (not method and
properties). You cannot create and use instance of module
as an object. In Class Module all public
procedures/functions and variables are methods and
properties of that class and you can create multiple
instances of that class using object valiables. For example

dim MyVar as MyClass

set MyVar=new MyClass
MyVar.DoSomething  'Call DoSomething method
set MyVar=nothing

probably you need to post you question to another
newsgroup to get more detail information

Val

Quote:
>-----Original Message-----
>What is diff. class Class Module & Module

>.



Sun, 20 Jun 2004 22:48:35 GMT  
 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



Sun, 20 Jun 2004 23:21:03 GMT  
 What is diff. class Class Module & Module
This site has answer to your question.
Thanks
http://www.vbwm.com/art_1997/ser_cls1.htm
Quote:
>-----Original Message-----
>What is diff. class Class Module & Module

>.



Mon, 21 Jun 2004 01:11:25 GMT  
 What is diff. class Class Module & Module

Quote:

> What is diff. class Class Module & Module

Use a class module (or a Type) to hold things you might want more than one
of.  You can use class modules to keep you from ever forgetting to turn
off the hourglass or close a file, even in case of an error:

 http://www.csdn.net/dev/Visual%20Basic/document/E-Tips/e-tips/e-tips1...

 http://groups.google.com/groups?selm=u2vbubhresc0b1%40corp.supernews.com

Note that this technique, called "resource management" or "resource
acquisition is initialization", can.NOT be done in what Microsoft seems
to be calling "the next version of Visual Basic".  Don't drink the
koolaid.

--
Joe Foster <mailto:jlfoster%40znet.com>     Greed = God? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Mon, 21 Jun 2004 02:27:55 GMT  
 What is diff. class Class Module & Module
That was a very good description.

As a newbie, I found it very useful and will now start using these wonderful
class modules

The Green Giant

--
At first there was nothing. Then God said 'Let there be light!'
Then there was still nothing. But you could see it.


Quote:
> 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



Mon, 21 Jun 2004 09:14:52 GMT  
 What is diff. class Class Module & Module
Good luck.

The biggest 'lie' in that excellent description is "Creating a class module is
simple". That's right, except that it runs afoul of the eternal bugaboo of code
reuse. It's *never* simple to write reusable code.

What typically happens is something like this. You write a program for a
specific purpose. In doing that you see an opportunity to create a reusable
class so you do so.

When you reuse the class in the next program however you find that the routines
aren't sufficiently generic-what worked perfectly in the first program doesn't
quite fit the second program. So you either 'break' the first program by
modifying the routine or add a second, almost identical routine, for the second
program. While the second approach works it's rarely better than just coding the
routine into the program in the first place.

Where writing class modules really works is when you have a bunch of programs in
simultaneous development which reuse the code. Given enough programs you'll
cover enough variables that the code you write in the class module will actually
handle everything. Otherwise it's an iterative process that involves eternally
'fixing' the earlier programs to account for changes required by later ones.

Quote:

> That was a very good description.

> As a newbie, I found it very useful and will now start using these wonderful
> class modules

> The Green Giant



Tue, 22 Jun 2004 03:43:19 GMT  
 What is diff. class Class Module & Module
I find it simple :-), and only write generic class modules or very specific
ones so as to keep it even simpler

Max Bolingbroke


Quote:
> Good luck.

> The biggest 'lie' in that excellent description is "Creating a class
module is
> simple". That's right, except that it runs afoul of the eternal bugaboo of
code
> reuse. It's *never* simple to write reusable code.

> What typically happens is something like this. You write a program for a
> specific purpose. In doing that you see an opportunity to create a
reusable
> class so you do so.

> When you reuse the class in the next program however you find that the
routines
> aren't sufficiently generic-what worked perfectly in the first program
doesn't
> quite fit the second program. So you either 'break' the first program by
> modifying the routine or add a second, almost identical routine, for the
second
> program. While the second approach works it's rarely better than just
coding the
> routine into the program in the first place.

> Where writing class modules really works is when you have a bunch of
programs in
> simultaneous development which reuse the code. Given enough programs
you'll
> cover enough variables that the code you write in the class module will
actually
> handle everything. Otherwise it's an iterative process that involves
eternally
> 'fixing' the earlier programs to account for changes required by later
ones.


> > That was a very good description.

> > As a newbie, I found it very useful and will now start using these
wonderful
> > class modules

> > The Green Giant



Tue, 22 Jun 2004 04:14:07 GMT  
 What is diff. class Class Module & Module
I reuse all the time...just remember what it takes to write generic code.  I
also like to remember the definition of a class...the data and the methods
to manipulate the data.  Remember that and your a happier man.  The people I
see having the most difficulty with classes are people who use them for
repositories of functions...that would be a module.

Designing and writing good classes, regardless of implementation language,
was one of my favorite classes in college.  I recommend a class like it to
everyone!

--
TNB (Tim Walsh - You might find me in the yellow pages!)


Quote:
> Good luck.

> The biggest 'lie' in that excellent description is "Creating a class
module is
> simple". That's right, except that it runs afoul of the eternal bugaboo of
code
> reuse. It's *never* simple to write reusable code.

> What typically happens is something like this. You write a program for a
> specific purpose. In doing that you see an opportunity to create a
reusable
> class so you do so.

> When you reuse the class in the next program however you find that the
routines
> aren't sufficiently generic-what worked perfectly in the first program
doesn't
> quite fit the second program. So you either 'break' the first program by
> modifying the routine or add a second, almost identical routine, for the
second
> program. While the second approach works it's rarely better than just
coding the
> routine into the program in the first place.

> Where writing class modules really works is when you have a bunch of
programs in
> simultaneous development which reuse the code. Given enough programs
you'll
> cover enough variables that the code you write in the class module will
actually
> handle everything. Otherwise it's an iterative process that involves
eternally
> 'fixing' the earlier programs to account for changes required by later
ones.


> > That was a very good description.

> > As a newbie, I found it very useful and will now start using these
wonderful
> > class modules

> > The Green Giant



Tue, 22 Jun 2004 04:32:20 GMT  
 What is diff. class Class Module & Module


Quote:
>Good luck.

>The biggest 'lie' in that excellent description is "Creating a class module is
>simple". That's right, except that it runs afoul of the eternal bugaboo of code
>reuse. It's *never* simple to write reusable code.

It requires thought, I'll grant you, and reuse is achieved far too
little, but it's far from impossible. Given how much VB developers reuse
other people's code (ADO, MSXML, FileSystemObject,
OLEDocumentProperties, a million third-party activeX controls, etc), we
should be pretty aware of what it takes.

Quote:
>Where writing class modules really works is when you have a bunch of
>programs in
>simultaneous development which reuse the code. Given enough programs you'll
>cover enough variables that the code you write in the class module will
>actually
>handle everything.

This is true; in my current project we have a reusable XSL transform
class which manages the caching of MSXML template objects in the ASP
application which is reused in many places in a large app. On the other
hand, it does a much more efficient job than the system in my previous
project, so I shall soon be using it there, and I expect it to pop up in
any future web apps that do xforms on the server.

--
Steve Walker



Wed, 23 Jun 2004 06:14:39 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Class modules 97 - Refering to array within a custom class module

2. Accessing procedures of a class module from another class module

3. Class Modules & Modules

4. Q(VB5) : Different between module & class module

5. Class Module & Module

6. What is diff. class Class Module & Module

7. What is diff. class Class Module & Module

8. What is diff. class Class Module & Module

9. Circular Reference Between Modules when 2 Class Modules Listen to Each others Events

10. Class Module and Module

11. VB Modules/Class Modules

12. class module vs. module

 

 
Powered by phpBB® Forum Software