ClassMicrosoft.VisualBasic.Interaction SyntaxDim result As Object = CallByName (objectRef, procName, _ useCallType, args( ))
DescriptionThe CallByName function provides a method for calling a class member by name. It calls any property accessor (get or set) or method and returns that member's return value, if available. The member name is sent as a string instead of as a design-time compiled member. Since procName is a string expression, it is possible to call routines dynamically at runtime using the name of the members. Usage at a Glance
ExampleThe following example uses a parameter array to call the Multiply method of a class named EasyMath: Module GeneralCode Public Sub TestCallByName( ) Dim mathTester As New EasyMath Dim testArguments( ) As Double = {1.0#, 2.0#, 3.0#} MsgBox(CallByName(mathTester, "Multiply", _ CallType.Method, testArguments)) ' Displays "6" End Sub End Module Public Class EasyMath Public Function Multiply(ByVal sourceValues( ) As Double) _ As Double Dim operationResult As Double = 1.0# Dim counter As Integer For counter = 0 To UBound(sourceValues) operationResult *= sourceValues(counter) Next counter Return operationResult End Function End Class See AlsoCall Statement |