Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 The different between "Class Moudle" and "Moudle"?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

EmilMatthew
Squire

China
11 Posts

Posted - Jul 27 2004 :  08:38:16 AM  Show Profile  Reply with Quote
I have seen some source code which were coded in VB with DirectX.
I can see the programmer use both "Visual Basic Class Moudle" and "Visual Basic Moudle",but what had confused me was that ,I didn't know the difference between the two.
Because as I thought,the code to be used in "Class Moudle" and "Moudle" was seen similar.
I didn't know much about what kind of function could only be declared in "Class Moudle" ,and what kind of function could be only used in "Moudle".
Thanks a lot!

VBBR
Moderator

Brazil
617 Posts

Posted - Jul 27 2004 :  10:34:55 AM  Show Profile  Reply with Quote
Any kind of function can be defined and used in both. The difference is, in a normal Module, you call the functions and variables directly (for example, "Result = CalculateResult(2, 4)", if you defined the CalculateResult function in some normal module. You can call this from anywhere in your program assuming the function is defined as Public. If you only want the function to be accessed from within the module in which it was defined, define it as Private. The same applies to variables.)

A class module is an object. Being so you need to define all functions and variables of it in its code, then, in another module define a instance of it, like this: (suppose you have a class module called Math)

Dim Ma1 as Math
Set Ma1 = New math

See? Then you can access the functions and variables inside Math through the instance called Ma1 (or whatever you decide to call it) this way:

Result = Ma1.CalculateResult(2, 4)

It's really simpler than it looks. This doesn't apply just to VB, it's a very common OO (object orientation) concept, and probably the most basic one. A Class Module is the same thing as a Class. (class is the most common name used in all programming languages)


Whatever. Who knows...
Go to Top of Page

sdw
Warrior

USA
160 Posts

Posted - Jul 27 2004 :  10:36:15 AM  Show Profile  Visit sdw's Homepage  Click to see sdw's MSN Messenger address  Reply with Quote
A Module is used to declare global things like variables, functions, and user defined types (plus more) which are then able to be used throughout the entire project. A class is kind of like a user defined type (a group of variables), only with its own functions. After you've built your class module you need to make a new instance of it in order to use it. You can do this by two means known to me:
  
'Say we named our class module to clsSomeObj
'1st way:
Dim myObject as new clsSomeObj  
  
'2nd way:
Dim myObject as clsSomeObj  
Set myObject = new clsSomeObj  
  


Hope that helped you. Go back to that sourcecode you have and look at how the programmer has used the Modules and Classes. BTW - it's not a "Moudle" it's a "Module" :)
Go to Top of Page

Sion
Warrior

Denmark
138 Posts

Posted - Jul 27 2004 :  10:45:39 AM  Show Profile  Visit Sion's Homepage  Click to see Sion's MSN Messenger address  Reply with Quote
I think you talking about Modules - not "Moudle".
The main difference is that classes (Class Modules) can be used create different instances from, while a Module is static and dosn't work the way objects, controls and classes do.
A class can work much like a Command Button; It can have properties, events, private and public functions and subs, and once you have built a class you can use it elsewhere in you code by creating instances of it. A module dosn't need to be initialized, so it's not possible to have module-objects. Modules can also have properties, events, private and public functions and subs as well as global variables that is available from anywhere in the project.
Classes are the key to Object Oriented Programming (encapsulation etc.) and can be used to imitate real-life objects, and modules are used to store repetative/general and global code.

Visit my personal blog at www.AndersNissen.com!
Go to Top of Page

EmilMatthew
Squire

China
11 Posts

Posted - Jul 28 2004 :  12:34:44 AM  Show Profile  Reply with Quote
Thank you so much ,I learned so much!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
VBGamer © Go To Top Of Page
This page was generated in 0.09 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.