Function Fname [(Arguments)] [As type]
[statements]
Functionname = expression
[statements]
Functionname = expression
End Function
Declares and defines a procedure that can receive arguments and return a value of a specified data type.
When the optional argument list needs to be passed the format is as follows:
([ByVal] variable [As type] [,ByVal] variable [As type] ]…])
The optional ByVal parameter specifies that the variable is [passed by value instead of by reference (see “ByRef and ByVal” in this manual). The optional As type parameter is used to specify the data type. Valid types are String, Integer, Double, Long, and Variant.
Refer to Variable types for additional information.
Sub Main Dim I as integer For I = 1 to 10 Print GetColor2(I) Next I End Sub Function GetColor2( c% ) As Long GetColor2 = c% * 25 If c% > 2 Then GetColor2 = 255 ' 0x0000FF - Red End If If c% > 5 Then GetColor2 = 65280 ' 0x00FF00 - Green End If If c% > 8 Then GetColor2 = 16711680 ' 0xFF0000 - Blue End If End Function