Jay B. Harlow [MVP - Outlook] wrote:
Steve,
1. How do I code an ObjectRef so that it can be stored in a variable.
"ObjectRef" is the name of the parameter, the type of the parameter is
"Object". Use any Object variable as the parameter. Remember that all
types
inherit from Object, so you can use any variable as the first parameter.
Dim i As Integer = 100
Dim o As Object
o = CallByName(i, "ToString", CallType.Method)
2. Can I reference methods in a module with a CallByName or similar
I don't see that Modules or Shared methods are supported, as they do not
have an instance of an Object associated with them. The ObjectRef
parameter
is required, you get an exception if you attempt to pass Nothing. This
makes
sense as I am certain that it is using Reflection to check the object to
see
if it has the method (without the object it would not know if it had the
method or not).
Also remember that multiple Modules can have a method with the same name
in
them.
Hope this helps
Jay
Thanks I had come to a similar conclusion. Modules just looked like a
convenient container for the project I'm working on, but I class works
nicely to.
RE: 1. I think you will find that while your analysis is ok, the example
will fail looking for Object 100.
Dim o As Object
o = MyObject ' Declared elsewhere in the solution
CallByName(o, "MyMethod", CallType.Method)
I'm having difficulty with CallByName.
Syntax ask for an ObjectRef as Object.
1. How do I code an ObjectRef so that it can be stored in a variable.
2. Can I reference methods in a module with a CallByName or similar
Thanks in advance
Steve