Showing posts with label Sub. Show all posts
Showing posts with label Sub. Show all posts

Wednesday, October 27, 2010

Parameters in Subroutines & Functions

Sometimes a behavior will require further information to accomplish a task. When an input is required for a behavior to execute, this input is passed to the procedure as one or a number of parameters (sometimes called arguments).

Code eg: Subprocedure using parameters.

Public Sub Login(Username As String, Password As String)
    ' Code does something
End Function

Code eg: Function using parameters.

Public Function Calculate(NumberOne As Integer, NumberTwo As Integer) As Integer
    ' Code does something
   Return AValue
End Function

Subroutines

A subroutine simply executes code when called by another procedure.

Code eg: Subroutine.

Public Sub CalculateScore()
        ' Declare variables
        Dim TotalDamage As Integer = 555
        Dim TotalAgility As Integer = 6
        ' Create the expression
        Dim TotalPoints As Integer = TotalDamage * TotalAgility
End Sub

A subroutine does not return a value to the calling procedure.

If you need to return a value - use a function.