Click to See Complete Forum and Search --> : modules


PanasonicSubz
December 9th, 1999, 05:34 PM
what is a module and please give me an example of what to do in one. whats the difference between a class module and a module? Please help me understand what a module is, thanks

PanasonicSubz

Chris Eastwood
December 9th, 1999, 05:50 PM
Didn't someone already answer this at http://codeguru.developer.com/bbs/wt/showpost.pl?Board=vb&Number=10671&page=&view=&sb= ?

A module is a '.bas' file that you add to your project in vb with the 'Project->Add Module' menu item. It can hold 'public', 'private' and 'friend' scoped variables and procedures / functions.

A typical BAS module might hold utility routines that need to be called from anywhere in your program (ie. forms/controls/classes/other modules).

For example, a BAS module might hold a routine that calculates a certain value based on parameters you pass to it, eg (in your BAS module MODULE1.BAS) :


public Function DaysTillChristmas() as Long
DaysTillChristmas = DateDiff("d", Now(), CDate("25/12/1999"))
End Function




This can then be called by any routine, anywhere in your VB program.

A class module identifies a 'blueprint' for an object. For example, you may have the idea of an 'employee' object in your program, so you'd add an 'Employee' Class module to your program :


private msName as string
private msJob as string

public property get Name() as string
Name = msName
End property

public property let Name(byval sName as string)
msName = sName
End property

public property get Job() as string
Job = msJob
End property

public property let Job(byval sJob as string)
msJob = sJob
End property




- Say you saved the above code in a class module called 'cEmployee.cls', your form (for instance) could then use the employee class to create employee-objects :



Dim oEmployee as cEmployee
Dim oEmployee2 as cEmployee
'
' Create two new employees
'
set oEmployee = new cEmployee
set oEmployee2 = new cEmployee

oEmployee.Name = "Mr Smith"
oEmployee.Job = "Managing Director"

oEmployee2.Name = "Henry"
oEmployee2.Job = "Janitor"




The help files (MSDN) that come with VB have tutorials on using modules / classes (and explain what they are probably better than I can) - if you can't be bothered to load the MSDN CD's into your machine, you can always read them online at http://msdn.microsoft.com


Chris Eastwood

CodeGuru - the website for developers
http://codeguru.developer.com/vb