hey guys, i am new to VB and am very disturbed on how to write modules n classes easily n quickly and what purpose the serve.
Printable View
hey guys, i am new to VB and am very disturbed on how to write modules n classes easily n quickly and what purpose the serve.
Well, I don't know a whole lot about modules, though I have used them, but classes is something I do know a little about. Basically, all a class does is allow you to reuse code. You can create an object from a class. The object then has all of the variables and functions that the class has. The functions can be accessed by the statement object .functionName. Unless I am getting mixed up with c++ anyway. Hope this helps.
If you new to Vb then you do not need to worry about classes for now..Quote:
Originally Posted by Harsh Gupta
As for modules well there a way really of keeping code in some form of order for example In a module you can write this
VB Code:
'notice its Public so all files in the project can see it Public Sub SayHello() MsgBox("Hello") End Sub
Now in a form you can write this
VB Code:
Private Sub Form_Load() Call SayHello End Sub
and it will run through the code in the SayHello() sub
Best thing you can do is not worry too much about these for now, get to grips with varibles and such like :)
Hope that helps and welcome to the forums :)
i know well enough about variables and contents related to them but i never get to learn about "writing" modules and classes.
can i write them just like copying api text from "api text viewer"?
Well, oridnary modules are another way to organize your code. You can have all the 3D stuff in one module, sound stuff in another, physics in another, game engine stuff in another, etc.
Class modules on the other hand are like objects, only without the objects. You give them properties, methods, and events (optional), but usually can be treated as a regular module only with some limitations, like for example, you can't do arrays. And you can declare a variable as your object. For example, let's say you have a class module called Enemy. Some properties in Enemy could be Visible, Life, Strength, etc. You can have functions/subs for that enemy in there that actually move the enemy. This is optional, but you can even create your own events for that enemy. Then when you are all set, you declare a variable as enemy.
VB Code:
Public My_Enemy(10) As New Enemy 'Creates 10 enemies
hope this helps in letting you know the difference in class modules and modules. Don't forget to rate my posts. ;)