Lesson 10 : Functions and Procedures (Sub Routines)

Introductions

You shouldn't need much of an introduction to sub-routines and functions : You already used them ! Look at the  following

examples of  routines from previous lessons.

Private Sub cmdOk ( )

        MsgBox "Hello Ma. Carmela D. Danganan"

End Sub

The only difference between a SUB ROUTINES and a FUNCTION is that a function returns a value and a sub routines

does not. Programmers uses sub routines and functions to break code into smaller task. This make the code easier to read and

debug.  Also sub routines can be called from different part of the program, reducing duplication.

10.1 Sub Routines

        The basic syntax for defining a subroutine is

    Sub name [( argument list)]

            [ statements ]

            [ exit sub ]

            [ statements ]

    End Sub

   

10.2 Functions

    Function name [( argument list )]

            [ statements ]

            [ Exit Function ]

            [ statements ]

            [ name = expression ]

    End Function