Passing a Function name as a procedure argument
WJG,
A good way to do this is to place your function(s) in a class module. Then
you can use the CallByName VBA method to "call" the desired function using a
string value...
Module Module1:
Sub test()
Dim M As New MathLibrary
CallByName M, "FuncA", VbMethod, 2345, 4321
CallByName M, "FuncB", VbMethod, 2345
End Sub
Class MathLibrary:
Public Function FuncA(a As Integer, b As Integer)
MsgBox "FuncA(" & a & "," & b & ")"
End Function
Public Function FuncB(a As Integer)
MsgBox "FuncB(" & a & ")"
End Function
BJ
" wrote in message
oups.com...
1. I have a Standard Module Function:
Public Function GetARoot(ByVal FirstGuess As Double, ByVal
FunctionName As _
String) As Double
that calculates the root of an equation.
I have several equations programmed as Functions in the Standard
Module. I wish to pass the name of one of these Functions as an
argument to "FunctionName" and call the Function with this name from
inside GetARoot.
Can this be done?
|