Well, since you posted this as a VB.Net question, I guess someone should show you how to do it in VB.Net since there are some differences.
The function declaration has several parts. The first deals with the scope of the function. The scope identifies where the function can be accessed from. The two main options are Public and Private. Public means that that function can be accessed from outside of the class itself. Private means that the function can only be accessed within the class that it is written.
For example:
Public Class Math
Public Function Multiply(...) As Double
Private Function MultiplySubFunction(...) As Double
End Class
If you have referenced the
Math
class within your form, then you can call the public function
Multiply
from within your form. However, because
MutliplySubFunction
is private, it is only accessible from code written within the Math class.
The next part tells what type of method this will be (
Function
or
Sub
). A Function returns a variable of whatever type you define it as. A Sub does not return anything.
Then, you have the name of the method. Following the name are a set of parentheses. It is within these parentheses that you define the variables that will be passed to the method.
In this example:
Public Function Multiply(ByVal firstNo As Double, ByVal secondNo as Double) As Double
you pass in two variables
firstNo
and
secondNo
. The variable declaration itself has several parts, so let's look at these.
The first identifies how the variable is passed (
ByVal
or
ByRef
). If you pass a variable
ByVal
the method will create a copy of the variable in memory. This means that no matter what you do to that variable, the original will not be affected. However, if you pass it
ByRef
, the method is just passed the address of the variable. Anything you do to a reference variable affects the original. In the case of
Multiply
we aren't being asked to change the original values, so we pass them
ByVal
.
The next part of the variable is the name of the variable. This is the name that you will use within that method. Lastly, you tell it what type of variable it will required. If you define it as an
Integer
, then if it can be implicitly converted to an Integer, it will be. For instance, if you declared
firstNo
as an
Integer
and passed it 24.56, it would round it to 25.
The full example would look like:
Public Function Multiply(ByVal firstNo As Double, ByVal secondNo As Double) As Double
Return (firstNo * secondNo)
End Function