Modules in Visual Basic

Edit ArticleEdit Article
Comments

Modules are containers to define custom functions, procedures or variables to group code in Visual Basic.

Module containing an entry point subroutine (main) is an entry module. It is always at least one module defined in the Visual Basic macro.

In order to add new module it is required to RMB (right mouse button click) the Modules folder and select Inset->Module command

Adding new module to the macro
Adding new module to the macro

Module must have an unique name which can be defined by the developer.

Module properties
Module properties

Functions defined in module are public. Members (variables) declared with Dim keyword are only visible within this module scope and not visible for another modules, while members declared with Public keyword are visible for this and other modules. Refer Variables Scope article for more information.

Module members
Module members

Module members are available in IntelliSense after typing the name of the module followed by . symbol.

IntelliSense for members defined in the module
IntelliSense for members defined in the module

Notifications

All articles and code at CodeStack are now open-source and hosted on GitHub. If you want to contribute by modifying existing articles and code snippets, submitting new ones, reporting errors and bugs etc. please follow this blog post for more information. We appreciate any contribution.


Product of Xarial Product of Xarial