I first came across modules while learning visual basic 6 a few years ago and the same concept applies in the newer visual studios versions as well (2003, 2005, 2008). The explanation and example of what a module is below (by Madboy of VBForums) is perhaps the easiest to understand.
A module is used to store all your functions and public routines seperately. Apart from it keeping your code editors window clean, it removes the need for repetitive typing. For example, it is better to add code to a module and use 1 line to call it when needed, then to repeat the same code over and over. This code from the module Exits the program when needed:
Public Sub ExitProgram()
It has to be named Public so VB knows it is available to all forms. Now, from the form, this code is called when you click either the File > Exit menu item or the Exit Command button, like so (This code goes in your form’s code window):
Private Sub mnuFileExit_Click()
Private Sub cmdExit_Click()
Leave a Reply