Calling a function/sub when a variable holds the name 
Author Message
 Calling a function/sub when a variable holds the name

I would like to construct the name of a subroutine or a
function in a variable then execute the sub/function.  
For example:

/* Example 1: */
/*  Trying to call function by name in a variable */

Dim c as Control, FunctionName as String

for each c in me.Controls
  if ( c.AccessibleRole = AccessibleRole.Text )
    FunctionName = c.Name & "_Validate"
    call FunctionName
  End If
Next

/* End example 1 */

Alternatively, I could create an array of FunctionName(s)
and AddessOf(s)... but then how can I execute a function
based on the AddressOf that function?

Any ideas?

Thanks for your time,
Patrick



Wed, 29 Sep 2004 02:00:28 GMT  
 Calling a function/sub when a variable holds the name
look at the MethodBase.Invoke Method, and the Dynamically Loading and Using
Types topic in the help fiels.  Both have examples of invoking by string

ms-help://MS.NETFrameworkSDK/cpref/html/frlrfSystemReflectionMethodBaseClass
InvokeTopic.htm
ms-help://MS.NETFrameworkSDK/cpguidenf/html/cpcondynamicallyloadingusingtype
s.htm

--
Regards

John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional Windows Forms
     ISBN: 1861005547
Professional JSP
    ISBN: 1861003625
Beginning JSP Web Development
    ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------


Quote:
> I would like to construct the name of a subroutine or a
> function in a variable then execute the sub/function.
> For example:

> /* Example 1: */
> /*  Trying to call function by name in a variable */

> Dim c as Control, FunctionName as String

> for each c in me.Controls
>   if ( c.AccessibleRole = AccessibleRole.Text )
>     FunctionName = c.Name & "_Validate"
>     call FunctionName
>   End If
> Next

> /* End example 1 */

> Alternatively, I could create an array of FunctionName(s)
> and AddessOf(s)... but then how can I execute a function
> based on the AddressOf that function?

> Any ideas?

> Thanks for your time,
> Patrick



Wed, 29 Sep 2004 11:13:45 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Calling a sub name held in a variable

2. Calling a sub or function using a variable through another sub or function

3. Automatic capitalization of variable names, type names, subs and functions

4. Returning sub or function name within a specific sub or function

5. Calling Sub/Function name?

6. Calling Functions or Subs with a variable

7. Refering to Functions and Subs held in one global template from another global template

8. Call Function using Func Name stored in variable

9. Calling a function based on a variable name

10. Retrieve name of current sub/function and name of current module

11. execute a variable as a function/sub procedure (like eval function in java(script))

12. How can I Call a Sub or Function Procedure with a Variable as Function or Procedure Name. Please Help

 

 
Powered by phpBB® Forum Software