Specifying the Data Type for a Functions Result

Like variables, functions can have types. The result of your function procedure can be a String, Integer, Long, etc. To specify the data type for your function's result, add the As keyword and the name of the desired data type to the end of the function declaration line. For example:

Function MultiplyIt(num1, num2) As Integer

If you don't specify the data type, Visual Basic assigns the default type (Variant) to your function's result. When you specify the data type for your function's result, you get the same advantages as when you specify the data type for your variables — your procedure uses memory more efficiently, and therefore it runs faster.

Let's take a look at an example of a function that returns an integer number, although the arguments passed to it are declared as Single in a calling subroutine.

0 0

Post a comment