Results 1 to 4 of 4

Thread: Calling procedure by string value (Resolved)

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    39

    Calling procedure by string value (Resolved)

    I have a table and in it I have over 100 procedure names, the procedures themselves are part of the applicaiton. Is it possible to get the value from the table and call the procedure accordingly without using any case or if statments. i.e. a string, Mystring will have a value Proc1 and using this value I will call Proc1.
    Last edited by stems; Jan 7th, 2006 at 10:55 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Calling procedure by string value

    You would need to use reflection.
    VB Code:
    1. 'Get the type of the current instance.
    2.         Dim myType As Type = Me.GetType()
    3.  
    4.         'Get a MethodInfo object by specifying the name of the method.
    5.         Dim myMethodInfo As Reflection.MethodInfo = myType.GetMethod("MethodName")
    6.  
    7.         'Call the method on the current instance with no arguments.
    8.         myMethodInfo.Invoke(Me, Nothing)
    This would be equivalent to:
    VB Code:
    1. Me.MethodName()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    39

    Re: Calling procedure by string value

    Thanks, I will read a little on reflection and give it a try.

  4. #4
    Fanatic Member
    Join Date
    May 2003
    Posts
    758

    Re: Calling procedure by string value

    Since this thread isn't marked as resolved, I will add Delegates. Give a search for Delegates and you will find additional information about them.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width