Consider, for example, a client application that evaluates expressions entered by the user by passing an operator to a COM component. Suppose you are constantly adding new functions to the component that require new operators. Using standard object access techniques, you would need to recompile and redistribute the client application before it could use the new operators. To avoid this, you can use the CallByName function to pass the new operators as strings, without changing the application.
The CallByName function allows you to use a string to specify a property or method at run time. The signature for the CallByName function looks like this:
The first argument, Object, takes the name of the object you want to act upon. The ProcedureName argument takes a string containing the name of the method or property procedure to be invoked. The CallType argument takes a constant representing the type of procedure to invoke: a method (Microsoft.VisualBasic.CallType.Method), a property read (Microsoft.VisualBasic.CallType.Get), or a property set (Microsoft.VisualBasic.CallType.Set). The Arguments argument, which is optional, takes an array of type Object containing any arguments to the procedure.
You can use CallByName with classes in your current solution, but it is most often used to access COM objects or objects from .NET assemblies.
Suppose you add a reference to an assembly that contains a class named MathClass, which has a new function named SquareRoot, as shown in the following code:
Function SquareRoot(ByVal X As Double) As Double
Return Math.Sqrt(X)
End Function
Function InverseSine(ByVal X As Double) As Double
Return Math.Atan(X / Math.Sqrt(-X * X + 1))
End Function
Function Acos(ByVal X As Double) As Double
Return Math.Atan(-X / Math.Sqrt(-X * X + 1)) + 2 * Math.Atan(1)
End Function
End Class

Join the conversation! Your thoughts help the community grow.