ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

41-Modules

A module is quite similar to a class but every module has exactly one instance and it does not need to be assigned to a variable and does not support an inheritance.

 

A module last a lifetime same as your program because all of its members are Shared. Modules access levels can be adjusted with the access modifier.

 

Example:

  • Open the Visual Basic, select “File” on the menu, hit new and create a new project.
    01_helloworld
  • The New Project dialog will appear.
    create2s
    Select “windows” in the project types, hit the “windows form application” in the templates and hit “ok“.
  • Go to the solution explorer. Right click the application, click add and select a Module.
    modulesf1
  • The add new Item dialog will appear and do the process like what is shown below.
    modulesf2
  • Add the following code in the Module1
  1. Module Module1
  2. Public Sub popUpMsg(ByVal msg As String)
  3. MsgBox(msg)
  4. End Sub
  5.  
  6. End Module
  • Design the form just like shown below.
    modulesf3
  • Go to the form design and double click a button to fire the click event handlerof it. Add this following code in the method.
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. popUpMsg("Hello World")
  3. End Sub

Output:

modulesf4

 

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!