Page 55 - Computing Book 8
P. 55
Developing Applications – Visual Studio Class 8
Modules:
Visual Basic application source code is structured into module files with a .vb suffix. By default,
Visual Studio creates a separate module file for each form in an application containing the code to
construct the form. For example, the code to create a form called Form1 will be placed in a module
file named Form1.Designer.vb. Similarly, any code that has been defined by the developer to handle
events from controls in the form will be placed by Visual Studio into a module file called Form1.vb.
Using modules in VB are recommended while creating a complex application as they save space in
your code and also assist to reuse of code like functions.
To create a program using modules follow these steps:
• Create a form with one text box and a button and
change the text to “Code from Module”.
• Right-click on the project from the solution
explorer window and go to Add and then go to
Module and click
• In the next window Module will be automatically
selected give the name to Module or just click on
Add.
• After that, you will see the Module1.vb will start
appearing in the solution explorer window and
the script window of the module will also open.
• In between the Module and End Module lines, we will add our Subroutine.
VB
{ information
Public Subroutine message box
Pre Define
Code
• Using an element from another form in a module requires a declaration with the name of
the form. In this case Form1.TextBox1 is the name of the element from the other form and
its text will appear in the vbinformation box with the title defined as a string.
• Now go back to the form and double click on the button to open the script window.
• It is highly recommended to use the comments while using code from a module to
remember its functionality. Commenting is easy in VB using a ‘ single quote.
• To use the Subroutine/Function in this form we
will simply write its name in this case Pakistan().
• The green line above the sub with a single ‘ quote
is the comment.
The City School /Academics/Computing Curriculum/Class 8/2020-2021 Page 54 of 75

