Function and Subroutine

Function - a procedure, non-event type that does work and returns a single

value


please take note that Public here-in is a VB reserved word and is part of the declaration (can not omitted)


ex.:


Public Function myFunt(int x, int y)


        ......

        ....

        return (1)


end Function

 

Note:


user can also use Function call inside any valid expression:


ex.:    

   curamt = estmate * 0.2 + CalTax() * 0.14


where:


   Public Function CalTax() as single

        ...

        ...

   End Function

Subroutine - a stand-alone non-event procedure that does work but does not return any value at all


ex.:


Public Sub Preletter(string mxx)


        ...

        ...

End Sub


Sub changes1(N as integer, S as integer)


        N = N * 2

        S = S * 2

End Sub


sample above will received arguments by reference and when the calling routines regains control it's two(2) local variables will be twice as much as they where before.


sub Nochanges2(byval N as integer, byval S as integer)


        N = N * 2

        S = S * 2

End Sub


sample above receives two(2) variable by Value and two(2) local variables value will not change after control are return to the caller.