CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: modules

  1. #1
    Join Date
    Nov 1999
    Location
    California, USA
    Posts
    40

    modules

    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

  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: modules

    Didn't someone already answer this at http://codeguru.developer.com/bbs/wt...age=&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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured