Don't really need to show code to explain them really. Modules are used for you to store functions, subs, constants, API's, and variables publicly or privately, and is a good way to organize code. For example, lets say you are making a game. You can store all the 3D engine code in one module, physics in another, API's and constants in another, the game engine in another, etc.
Class modules are used for making your own objects. You can store functions, subs, and variables in there like a module, but it has limitations. Like for example, you can't use arrays. Unlike regular modules, class modules can have properties, methods, and events, like you see with objects you would normally see in a form, like command buttons, textboxes, etc. After writing some code to a class module, you would need to do either this, which is called Early Binding:
VB Code:
Dim MyObject As MyClassModule
Private Sub Form_Load()
Set MyObject = New MyClassModule
End Sub
Or this, which is called loose binding:
VB Code:
Dim MyObject As New MyClassModule
Or this which is called Late Binding:
VB Code:
Private Sub Test()
Dim MyObject As MyClassModule
Set MyObject = New MyClassModule
End Sub
Now MyObject can access the code within a class module. You would do something like so to do it:
VB Code:
Private Sub Test()
MyObject.MyFunction
End Sub
Hope this helps.
Last edited by Jacob Roman; Jul 10th, 2005 at 10:21 AM.
You just need a type for enemies, I would think. That way you could link the description, the Mode of Operation MO, and any other relevant info in the base type. Then you could use something like this;
Yes, but you would need to set up a Class Module or Type first. It seems like you have the idea of how to use it down though. Here is a decent tutorial on custom Classes: http://msdn.microsoft.com/library/de...sesobjects.asp
Its for Microsoft Office and VBA but you can totally apply it to VB6. It is slightly hard to understand, but I used it as a starting point for making my first Class (which I am in the middle of making). Also when you go to Add a class module try using the Class Wizard. Let me know if you need help getting started with it.
^^ Late binding = Semi-OK but don't use if you can help it
Originally Posted by Jacob Roman
VB Code:
Dim MyObject As New MyClassModule
^^ Loose Binding = Very Bad
A user-defined type (Hate that name, it is a structure really) is just a block of data. Whereas a class module is a full-blown object with its own executable code contained within.
Yes. Your class CEnemy would need a Name property, however that is reserved by VB, so it would have to be EnemyName or something like that. And yes you need to do Set Enemy(0) = New CEnemy.
Xypherx, I strongly reccomend opening a new project, adding a class module, and when the window pops up instad of select Blank Class Module, select VB Class Builder. Then play around with adding methods, and properties, then look at the code that VB writes for you.
Someone will still have to write/link a tutorial for you or you can use the confusing one I mentioned early to understand the property Let Get part. I actually hope someone has a good tutorial, I could use one too.
that tutorial you sent me confused me so much for some reason. but ill try what you said, and yes i really do hope somebody writes/links a tutorial for us
Your right, it uses very complex language (for no reason at all, some authors are just weird). But its the only one I know of (obviously there are others).
The part of property let get set explains it enough that after you use the VB Class builder you should be good to go.
By the way, after you use the class builder to make the original file you can go back to it (go to make a new class then select it just like you did before) and edit/add things to the class you made and VB will pop the code in at the proper spot.
Nope. If you tried, you would have gotten an error. From MSDN:
Enumeration variables are variables declared with an Enum type. Both variables and parameters can be declared with an Enum type. The elements of the Enum type are initialized to constant values within the Enum statement. The assigned values can't be modified atrun time and can include both positive and negative numbers. For example:
An Enum statement can appear only atmodule level. Once the Enum type is defined, it can be used to declare variables, parameters, orprocedures returning its type. You can't qualify an Enum type name with a module name. Public Enum types in aclass module are not members of the class; however, they are written to thetype library. Enum types defined instandard modules aren’t written to type libraries. Public Enum types of the same name can't be defined in both standard modules and class modules, since they share the same name space. When two Enum types in different type libraries have the same name, but different elements, a reference to a variable of the type depends on which type library has higher priority in the References.