Understanding automation : How is automation coding structured? : Using functions and subroutines |
VBA uses both functions and subroutines (or subs). Functions can be used to return a value, but subs cannot.
In VBA, functions and subs do not need to be declared before they are used, nor before they are defined. In fact, functions and subs need to be declared only if they actually exist in external system DLLs.
Typical functions in a language such as Java or C++ can be structured as follows:
void foo( string stringItem ) { |
// The body of the function goes here |
} |
double bar( int numItem ) { return 23.2; } |
In VBA, however, functions are structured as in the following example:
Public Sub foo (stringItem As String) |
' The body of the subroutine goes here |
End Sub |
Public Function bar (numItem As Integer) As Double bar = 23.2 |
End Function |
To force a function or sub to exit immediately, you can use Exit Function
or Exit Sub
(respectively).
Copyright 2013 Corel Corporation. All rights reserved.