|
|
Title | Invoke a function by name using CallByName |
Keywords | CallByName, execute, invoke, call, function, subroutine |
Categories | Tips and Tricks, Software Engineering |
|
|
When the user clicks the Evaluate button, the program uses CallByName to invoke the function selected by the cboMethod ComboBox.
|
|
Private Sub cmdEvaluate_Click()
Dim result As Variant
result = CallByName(Me, cboMethod.Text, VbMethod, _
txtParameter)
lblResult.Caption = Format$(result)
End Sub
Public Function Root(ByVal X As Single)
Root = Sqr(X)
End Function
Public Function Square(ByVal X As Single)
Square = X * X
End Function
Public Function Triple(ByVal X As Single)
Triple = 3 * X
End Function
|
|
Note that CallByName is slower than invoking a function directly.
|
|
|
|
|
|