Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Module vs Class Module


I have gone to the VBA help files to try to find the difference and I am
no better now than before.

A Class Module:
A module that contains the definition of a class, including its
property and method definitions.

A Standard Module:
A module containing only procedure, type, and data declarations and
definitions. Module-level declarations and definitions in a standard
module are Public by default. A standard module is referred to as a
code module in earlier versions of Visual Basic.

What is the purpose of a class module and when should it be created?


--
DCSwearingen


------------------------------------------------------------------------
DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=501243

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Module vs Class Module


Hello DCSwearingen,

Class modules are used to create custom objects. These objects don't
have to be visible like a Window or control. They can be objects like a
Collection. The objects have Properties that are defined by the Let,
Get, and Set statements in VBA. Methods are created using Subs and
Functions. These can be either Public (Global in scope) or Private
(Local in scope - for the Class' use only). Class modules are sometimes
referred to as "In-process Servers".

You can create one whenever discover you need an object to perform
certain functions that don't already exist. To use the Class object,
you use the Dim statement. For example: Dim myObj As New MyClass

The first reference to the object in your code will create an instance
of the object. The object's lifetime depends on where it delcared, just
like other objects and variables. This is just an overview and not a
thorough explanation , but I hope it helps you to better understand
what a Class module is.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=501243

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Module vs Class Module

Simply, a Class module serves as the "cookie cutter" of an object.

Example: behind the scenes, Excel has class modules for Workbook, Worksheet,
Range, Chart, etc. objects. Every time you reference any property or method
of those objects, their Class modules determine how Excel responds/behaves
(i.e., return or set a value, do something else).

One reason to create your own Class module would be if you wanted to create
an object with it's own Properties and Methods. Say a class for Customer,
Account, OrderItem, Transaction, Employee, Task, etc. An object is a data
structure that can be held in memory and can be easily manipulated and will
behave according to your pre-determined business rules and instructions:
Customer.Address, Transaction.Date, Employee.Age, OrderItem.Price,
Customer.UpdateBalance, Customer.AvailableCredit etc.

If something is going to be subject to a lot of processing (and/or you have
a lot of 'somethings'), loading info into a class object, putting that
object into a collection and then doing your processing can be a lot faster
and efficient than repeatedly reading & writing data to a spreadsheet.

And, aside from application-specific issues like Input & Output, a given
Customer class will behave the same in Excel or Access, so re-use and
portability can be an advantage as well.

All in all, this might come under the heading of: if you need it, you'll
know it. :-)

Microsoft Office XP Developer's Guide: Chapter 11: Custom Classes and
Objects
http://msdn.microsoft.com/library/de...sesobjects.asp

VBA Developers Handbook: Chapter 6: Creating Dynamic Data Structures Using
Class Modules
http://msdn.microsoft.com/library/de...smod ules.asp


HTH,
--
George Nicholson

Remove 'Junk' from return address.


"DCSwearingen"
wrote in message
news:DCSwearingen.21leca_1137188104.8586@excelforu m-nospam.com...

I have gone to the VBA help files to try to find the difference and I am
no better now than before.

A Class Module:
A module that contains the definition of a class, including its
property and method definitions.

A Standard Module:
A module containing only procedure, type, and data declarations and
definitions. Module-level declarations and definitions in a standard
module are Public by default. A standard module is referred to as a
code module in earlier versions of Visual Basic.

What is the purpose of a class module and when should it be created?


--
DCSwearingen


------------------------------------------------------------------------
DCSwearingen's Profile:
http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=501243



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Module vs Class Module


:) I am not a programmer by any means.

I have used the help files and this forum to learn what I do know and
am starting to use some of the things I pick up here.

I saw the Class module when I was inserting a new module and wa
wondering how I could use it.

I definitely need to do more reading.;

--
DCSwearinge

-----------------------------------------------------------------------
DCSwearingen's Profile: http://www.excelforum.com/member.php...fo&userid=2150
View this thread: http://www.excelforum.com/showthread.php?threadid=50124

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Module vs Class Module

In 99% of all cases you don't need to worry about class modules. Regular
modules will do very nicely. Exceptionally little of the code presented on
this site is designed for class modules. Most of the code you will find
anywhere for VBA is for regular modules. If you are just learning you should
probably just stick with regular module and the "Procedural" code that they
use. Just my two cents...
--
HTH...

Jim Thomlinson


"DCSwearingen" wrote:


:) I am not a programmer by any means.

I have used the help files and this forum to learn what I do know and I
am starting to use some of the things I pick up here.

I saw the Class module when I was inserting a new module and was
wondering how I could use it.

I definitely need to do more reading.;)


--
DCSwearingen


------------------------------------------------------------------------
DCSwearingen's Profile: http://www.excelforum.com/member.php...o&userid=21506
View this thread: http://www.excelforum.com/showthread...hreadid=501243


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
class module? sybmathics Excel Programming 17 February 25th 06 02:29 PM
Class Module & Module Liedson31 Excel Programming 1 June 8th 05 11:09 AM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 12:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"