SUB statement

Top  Previous  Next

Sub name [ (parameterlist) ]

   [ statements ]

   [ Exit Sub ]

   [ Return ]

   [ statements ]

End Sub

 

Declares the name, parameters and code that define a Sub procedure.

 

The parameter list contains one or more variables separated by a comma, the datatype must not be declared. Parameters by reference must be declared by using the BYREF directive.

 

You can use "Return" or "Exit Sub" statement to exit a sub.

 

Use a FUNCTION statement when you need to return a value to the calling code. Use a SUB procedure when you do not need to return a value.

 

Example:

Sub ComputeTotalPixels(length, width, ByRef total)

 

   ' -1 indicates an error

   total = -1

 

   ' exit immediately if length or width is zero

   If (length = 0) Or (width = 0) Then

      Exit Sub

   End If

 

   total = length * width

End Sub




Translate document: