Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
CLASS MODULE & SIMPLE MODULE | Excel Discussion (Misc queries) | |||
class module? | Excel Programming | |||
Class Module & Module | Excel Programming | |||
Variable from a sheet module in a class module in XL XP | Excel Programming |