Wednesday, October 27, 2010

Programming Behavior

Each behavior of a class is implemented as a procedure. A procedure may be a subroutine or a function.

Procedures may or not require parameters to execute.


Subroutine
When the behavior simply needs to execute some code, we use a subroutine.

Code eg 1: Subroutine with no parameters
Public Sub NameOfBehavior()
    'Code does something
End Sub
Code eg 2: Subroutine with parameters

Public Sub Login(UserName: String, Password: String)
    'Code does something with parameters...
End Sub


Function
When the behavior is required to return a value to calling procedure, we use a function.

Code eg 1: Function with no parameters
Public Function NameOfFunction() As String
    'Code does something
    Return "Sample return String"
End Sub
Code eg 2: Function with parameters

Public Function getLastName(FirstName: String) As String
    'Code does something with parameters...
    Return LastName
End Sub

No comments:

Post a Comment