Module...End Module Statement

   
Module...End Module Statement

Syntax

   accessmodifier   Module   modulename   '   statements   End Module 
accessmodifier (optional)

Type: Keyword

One of the following keywords determine the visibility of the module:

Public

Makes the module visible to all applications

Friend

Makes the module visible throughout the project

modulename (required)

Type: String literal

The name of the code module

Description

Defines a code block as a code module

Rules at a Glance

  • If accessmodifier is omitted, the module is Public by default.

  • modulename follows standard Visual Basic naming conventions and must be unique within its assembly.

  • statements can consist of the following:

    • Constant and variable definitions

    • Function and procedure definitions

Programming Tips and Gotchas

  • Code modules are similar to classes in which the public variables are treated as static fields and the public functions and procedures are treated as static (shared) methods . This means that, particularly in the event of a naming conflict (where two routines in different code modules have the same name), you can qualify the function or procedure with the name of the module in which it resides. For example, if the SayHello procedure is found in a module named modLibrary, it can be called as follows:

     modLibrary.SayHello(  ) 
  • Although modules are similar to classes, there are some important differences. The members of a module have scope equal to the module's containing namespace, rather than just to the module itself. Also, modules cannot be instantiated , do not support inheritance, and cannot implement interfaces.

  • If a code module is to contain a routine that serves as a program entry point, that routine must be named Sub Main . It must also have Public scope.

VB.NET/VB 6 Differences

The statement is new to VB.NET. VB 6 placed each code module in a separate BAS file, which rendered beginning and ending statements unnecessary. A single VB.NET file, on the other hand, can contain multiple code modules and classes, thus necessitating the use of beginning and ending statements.

See Also

Class Statement

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net