Defining a function

A function is defined in a similar way to a procedure, but with a few important differences:

♦ The keyword Function is substituted for Sub. End Function replaces End Sub. For example, if you wanted to declare a function named thisOne then you would need to write Function thisOne().

♦ You can specify zero or more parameters along with their data types. For example, if you wanted to declare a function named thisOne that would use one integer parameter called x, then you would need a statement like: Function thisOne (x As Integer).

♦ The function must return a certain type of value. This is specified after the argument list. For example, if you wanted to declare the function thisOne that would use one integer parameter x, and return a Currency value, you would write the declaration Function thisOne(x As Integer)As Currency.

♦ You return a value by assigning it to the name of the function.

0 0

Post a comment