JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Creating Modules

Traditionally in Visual Basic, you used modules to divide your code up into smaller units, because modules were designed primarily to hold code. Here's an example from Chapter 2:

Module Module1
    Sub Main()
        System.Console.WriteLine("Hello from Visual Basic")
        System.Console.WriteLine("Press Enter to continue...")
    End Sub
End Module

However, as mentioned earlier, modules can now hold methods, fields, properties, and events, just as classes can. There are a number of differences between classes and modules, though-see the In Depth section of this chapter for the details.

You create a module with the Module statement:

[ <attrilist> ] Module [ Public | Friend ] name
   [ statements ]
End Module

Here are the parts of this statement:

  • attrlist-Optional. List of attributes for this module. Separate multiple attributes by commas.

  • Public-Optional. Modules declared Public have public access, which means there are no restrictions on the accessibility of public modules.

  • Friend-Optional. Modules declared Friend have friend access, which means they are accessible from within the program that contains their declaration and from anywhere else in the same assembly.

  • name-Required. Name of the module.

  • statements-Optional. Statements that make up the variables, properties, events, and methods of the module.

  • End Module-Ends a Module block.

Each attribute in the attrlist part has the following syntax:

<attrname [({ attrargs | attrinit })]> Attrlist

Here are the parts of attrlist:

  • attrname-Required. Name of the attribute.

  • attrargs-Optional. List of arguments for this attribute. Separate multiple arguments by commas.

  • attrinit-Optional. List of field or property initializers for this attribute. Separate multiple initializers by commas.

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor