want to know how module are used in Visual studio

Posted on 2011-05-06
Last Modified: 2012-06-22
I just have problem
in understanding
the use
of Module
in a windows application
in they are used
and what is the difference between the class
and the module in win apps

Please provide me Stepwise Solution
Question by:code_me
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    A Module is just a Special Class that is Shared so you don't have to instantiate it before use.  Anything that is public in a Module can be accessed just by using its name from anywhere in your project.

    A regular class needs to be instantiated first with the new keyword and you need that specific reference variable to access the members within it.

    The Shared members of a regular class can be accessed without creating an instance of the class by using the name of the class, followed by a period, then the member name: "Class1.SomeMember"
    LVL 1

    Author Comment

    can a function
    stated under a module
    can also be accessed
    from anywhere
    in the project

    or is there any other process to achieve this
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Correct...a public sub/function in a module can be accessed from anywhere in the project.

    It can also be achieved with shared members of a class (which is what a module really stated previously):

        Public Class Class1

            Public Shared Function Foo() As String
                Return "FooBar"
            End Function

        End Class

    Now you can access Foo() from anywhere using syntax like this:

    LVL 69

    Expert Comment

    by:Éric Moreau
    if possible, do not use Modules. they are coming from the legacy (prior to .Net) and were implement to ease the migration from legacy VB to VB.Net
    LVL 16

    Accepted Solution

    You have to think of modules not as special case classes,  but instead as global space.  If you need a global variable in your project, a module is the place to put it.  If you have library functions (i.e. general purpose functions you might use in many places of your code) them a module is a good place to put it.

    Some examples that I personally have are the functions 'AppendSlash', 'CreatePath', and 'Trim and Remove Quotes".  ApendSlash takes a string, returns the same string, but with an ending '\' appended to the end of it if there was not already a slash here.  CreatePath takes a string like "C:\FolderA\FolderB\FolderC" and executes the required "MakeDir" commands for the parts of that path that do not already exist.  TrimAndRemoveQuotes takes a string, executes a Trim, then looks at the left and right most characters of the string.  If these are matching quotation marks they are removed.

    As you can imagine, these functions are very general purpose, are not really linked to a specific kind of class, and get used over and over and over to simplify tasks I find myself doing repeatedly.  These kinds of functions I place in modules.
    LVL 1

    Author Closing Comment


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    while loop over for loop 7 69
    countClumps  challenge 10 70
    java continue statement 10 53
    wordmultiple challenge 12 67
    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now