+ Reply to Thread
Results 1 to 2 of 2

Calling an arbitrary sub/function

  1. #1
    Registered User
    Join Date
    05-04-2005
    Posts
    2

    Calling an arbitrary sub/function

    Calling arbitrary subs/functions.

    I am trying to write a sub which executes an arbitrary second sub/function, defined by a string which contains the name and parameters of the second function.

    My first try was this:

    Sub Runsub(formula as string)

    If formula = "" Then

    Exit Sub

    End If

    Call formula

    End Sub

    where formula would take the form SubName(Param1, Param2, ...)

    but this refuses to compile.

    Any ideas?

  2. #2
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    something like this is working for me:

    Sub Runsub(myformula As String)

    If myformula = "" Then
    Exit Sub
    End If

    a = Evaluate(myformula)
    MsgBox a

    End Sub


    Sub test()
    Call Runsub("myAdd(2,3)")
    End Sub


    Function myAdd(x, y)
    myAdd = x + y
    End Function



    Maybe you could modify it as per your requirement.

    - Mangesh

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1