Paradigm wrote:
I tried Eval and it does seem to run the function but the function
displays a form used as a progress counter and the form is not displayed.
In essence I have a continous form with about 50 records in it and
the user can select any number of these. For each selection there is a
function to run. My progress form shows which of the functions is currently
running and how far through the function it is. All of this is working except
being able to call the function using the function name stored as a string in a
table. Alex
Perhaps the following brute force method is adequate:
Form code:
Dim varArray() As Variant
ReDim varArray(1)
varArray(0) = "My string"
varArray(1) = 3
MsgBox (EvaluateFuncti on("Function2" , varArray()))
ReDim varArray(0)
varArray(0) = "New string"
MsgBox (EvaluateFuncti on("Function1" , varArray()))
Module code:
Public Function EvaluateFunctio n(strFunctionNa me As String, varArray()
As Variant) As Variant
Select Case strFunctionName
Case "Function1" : EvaluateFunctio n = Function1(varAr ray())
Case "Function2" : EvaluateFunctio n = Function2(varAr ray())
Case Else
EvaluateFunctio n = strFunctionName & " is not in the function list."
End Select
End Function
Private Function Function1(varAr ray() As Variant) As String
Function1 = varArray(0)
End Function
Private Function Function2(varAr ray() As Variant) As Integer
Function2 = varArray(1)
End Function
Disclaimer: It's late and I'm tired. I didn't know if you needed
function arguments so I added varArray() for that purpose. Perhaps
ParamArray can be used to preserve argument names. Where's that
Functions collection Evaluate method hiding :-)?
James A. Fortune
I wonder if "works like a charm" only refers to charms that always
work.