Calling Function Procedures

Usually, you call a function procedure you've written yourself the same way you call a built-in Visual Basic function such as Abs — that is, by using its name in an expression. For example, the following is a function that calculates the rate of single-occupancy vehicle users in a community.


Function PercentSOV(SOV, sharedMotorized, nonMotorized)
    Const nmFactor = 0.2
    totalSOV = SOV - nmFactor * nonMotorized
    totalPossibleTrips = SOV + sharedMotorized + nonMotorized
    PercentSOV = (totalSOV / totalPossibleTrips) * 100
End Function

All of the following statements call the PercentSOV function.


If PercentSOV(SOV, Bus, BikeOrWalk) > 72 Then Debug.Print "Too high"
Application.StatusBar = 100 - PercentSOV(SOV, Bus, BikeOrWalk)
X = PercentSOV(SOV, Bus, BikeOrWalk)

The information that must be supplied to a procedure for it to perform its task — SOV, Bus, and BikeOrWalk in the preceding example — is passed in the form of arguments. For more information about arguments, see "Communicating with Procedures Using Arguments" later in this chapter.