EmilMatthew
Squire

China
11 Posts |
Posted - Jul 27 2004 : 08:38:16 AM
|
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
|
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... |
 |
|
sdw
Warrior
  
USA
160 Posts |
|
Sion
Warrior
  
Denmark
138 Posts |
Posted - Jul 27 2004 : 10:45:39 AM
|
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! |
 |
|
EmilMatthew
Squire

China
11 Posts |
Posted - Jul 28 2004 : 12:34:44 AM
|
Thank you so much ,I learned so much! |
 |
|
|
|