VBA - Passing a FUNCTION as an Argument
James, A function is not a datatype, so you cannot say Arg_Function as
Function, you have to use the datatype that the function returns, or
variant.
Here is a simple working example
Sub test()
MsgBox Func1(Func2, 9)
End Sub
Function Func2() As Long
Func2 = 7
End Function
Function Func1(arg1, arg2 As Long) As Long
Func1 = arg1 * arg2
End Function
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
"James B" wrote in message
...
Some expert help is required on this one. I want to
create a VBA function that calculates the derivative of
another function between two points.
The syntax would be something like the following:
Gradient = DerFun(Height(), x1, x2)
where
Function DerFun(Arg_Function as function, point1, point2)
DerFun=(Arg_Function(point2)-ArgFunction(point1))/ _
(point2-point1)
End Function
What is the proper syntax, instead of "Arg_Function as
Function"?
|