Three VisualBasic(VB) Modules are:
- Form module
- Standard module
- Class module
A module consist declarations and procedures.
Declaration contains declaration of variables, types, constants, dynamic link libraries. Procedures contains sub-procedures, event procedures, sub-functions.
The three modules namely, form, class, standard got its own extensions. Every Form module has .frm extension, class module has .cls extension and standard module has .bas extension.Creating module in VB is simple. Open the VB IDE and choose create standard exe. Click Right button of mouse in any blank area in project explorer window and select Add from the pop-up. In it there are items like Form, MDI Form, Module, Class module etc. The Module item can be used to create standard module(.bas extension). And Class Module is used to create class (.cls extension) module. If you want to create standard module select the Module from the list and if it is class module you want then hit the ClassModule.
When you make your choice then a new code window appears. In this code window you can put the necessary declarations and procedure whatever you want.
For example
Now we can create module
In the above figure (the window named Add Module) click the Open button.
Type above code( above given sub procedure and Function) into the newly created module .
Return to form and double click the button and type the code into procedure
form1 Code window (Opens on double clicking of command button control on form)
Now run the program and click the buttons
After these steps check the Project Explorer window(usually visible on right side of the IDE), see below figure
There are two items, Form and Modules contains the form module and standard module. The extension .frm in Form1.frm means form module and .bas in Module1.bas means standard module By selecting Project menu from menu bar shows list of items. There is also Add module and class module options available.
Public Sub modSub() MsgBox "Welcome to VB Module" MsgBox "This is From sub procedure in module" End Subor you can define function
Public Function modFun(str As String) As String modFun = str + " button pressed.Standard module working" End FunctionLet's try an example by creating an application that have a form and two command buttons as in figure.
Now we can create module
In the above figure (the window named Add Module) click the Open button.
Type above code( above given sub procedure and Function) into the newly created module .
Return to form and double click the button and type the code into procedure
Private Sub Command1_Click() Call Module1.modSub End Sub Private Sub Command2_Click() a = modFun(Command2.Caption) Label1.Caption = a End SubModule1 can be the property name of the module you created
form1 Code window (Opens on double clicking of command button control on form)
Now run the program and click the buttons
After these steps check the Project Explorer window(usually visible on right side of the IDE), see below figure
There are two items, Form and Modules contains the form module and standard module. The extension .frm in Form1.frm means form module and .bas in Module1.bas means standard module By selecting Project menu from menu bar shows list of items. There is also Add module and class module options available.
VB program code does not come line by line. Instead they are separated in code files called
modules, each of them is separated into procedures. Thus, VB
program becomes well structured which is the key part of developing
Visual Basic applications easily.
Source:Books,Internet
No comments:
Post a Comment