• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

want to know how module are used in Visual studio vb.net

I just have problem
in understanding
the use
of Module
in a windows application
in vb.net.How they are used
and what is the difference between the class
and the module in win apps

Please provide me Stepwise Solution
0
code_me
Asked:
code_me
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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"
0
 
code_meAuthor Commented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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 is...as 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:

    Class1.Foo()
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Éric MoreauSenior .Net ConsultantCommented:
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
0
 
HooKooDooKuCommented:
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.
0
 
code_meAuthor Commented:
thanks
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now