
Originally Posted by
melvados
A module? Could you explain to me in detail how to do it?
Sorry for the inconvenience caused.
Sometimes you need to create functions that are of generic in nature. Lets say you need a function which should give you a random number between specified range. So you will create a function to generate a random number and put into a module. Once you write this function in a module, you will be able to call it from anywhere.
A module is declared with Module, End Module pair. You don't need to create the object of the Module to call functions inside it. Here is some sample code:
vb.net Code:
' Module code
Module Module1
Public Function GetRandomNumber( _
ByVal minValue As Integer, _
ByVal maxValue As Integer _
) As Integer
Dim RandomClass As New Random()
Return RandomClass.Next(minValue, maxValue)
End Function
End Module
vb.net Code:
' Form code
Public Class Form2
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MessageBox.Show(GetRandomNumber(10, 20).ToString)
End Sub
End Class