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.
- Open the Visual Basic, select “File” on the menu, hit new and create a new project.
- The New Project dialog will appear.
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.
- The add new Item dialog will appear and do the process like what is shown below.
- Add the following code in the Module1
- Module Module1
- Public Sub popUpMsg(ByVal msg As String)
- End Sub
- End Module
- Design the form just like shown below.
- Go to the form design and double click a button to fire the click event handlerof it. Add this following code in the method.
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- popUpMsg("Hello World")
- End Sub