Changes

Jump to: navigation, search

Visual Basic Modules and Procedures

180 bytes added, 15:26, 31 July 2007
Visual Basic Code Modules
When writing additional Visual Basic for an application, the code should ideally be logically grouped to together with other source code in a module file. When we say ''logically grouped'' we mean that the code should be grouped with other code of a similar nature. For example, code to work with files might be placed in a module called FileIO.vb, while mathematical procedures might all reside in a file name Math.vb. The idea is to ensure Visual Basic code is placed in a file where it make sense for it to be located. This will differ between applications, but it is worth investing the time to ensure code is well structured as doing so makes subsequent maintenance of the code by you or other developers much easier.
We mentioned previously that Visual Studio places the code to construct each form in separate module files. We now need to learn how to create a new module in a project to contain our own Visual Basic code. Begin by creating a new Windows Application project in Visual Studio called ''vbModules''. Add two TextBox controls (named value1 and value2) , a button (named calculate) and a Label (named result) to the Form so that the form appears as follows: [[Image:Exampl.jpg]]  Once the new project has been opened and the first form is visible, select ''Add Module...'' from the ''Project'' menu. The ''Add Item'' window will appear with the ''Module'' item pre-selected:
[[Image:Exampl.jpg]]

Navigation menu