The most basic function you need to provide one variable in the argument list which is going to accept the value of the Array you will pass to it.
Most of the time you will pass the reference byRef. ByRef is the default in Visual Basic, so you do not need to explicitly state this. You can also state a type for your Array variable, but the Type definition is optional. For arrays I always type them as a Variant in the Sub procedure and do not state a type in the Function. If you do not Type the variable in the function it will adopt the type of whatever variable is passed to it.
Here's an example
Code:
Sub CountArray()
Dim arrayItem as Variant
Dim nCount as Integer
' create a quick array
arrayItem = Array(1,2,33,56,76,89,10)
' call the function to get the array count
nCount = fCountArray(arrayItem)
MsgBox "My Array has " & nCount & " Items in it"
End Sub
' Gets the count of the Array Items
Private Function fCountArray(arrayVar)
fCountArray = Ubound(arrayVar)
End Function
Notice if you are passing the entire array you use only the array name without the parenthesis.
myArray If you are passing a single array value you must use the array name with the parenthesis and the number of the item
myArray(3).
If you are calling a function within the same module you may use a Private Function. If you will need to call the function from outside the module you must use a Public Function or using "Function" without the "Private" directive preceding it will be public. You may want to use a Public Function while developing your code so you can test it by calling it from the Debug window.