Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003

    Unanswered: run sub with string


    is there a way that i can call a sub using a string?

    for example, i have 2 subs:

    public sub run1()
    do something...
    end sub

    public sub run2()
    do something...
    end sub

    I have another sub which will run one of the above subs based on a parameter:

    public sub runSub(n as integer)
    call "run" & n <---how do i do this???
    end sub

    So in effect, i'll place code on a control which will then automatically run one of the subs based on the above procedure:

    private sub btn_click()
    end sub

    is this possible? I'm looking to find a way to call the routine in a single piece of code and based on the parameter, run a particular sub/routine.

    this is useful to streamline coding where there is a repetition of subs differed by name --- ie. sub1, sub2, sub3, sub4

    Anybody know?

  2. #2
    Join Date
    Sep 2004


    If you have them in a form you can within that for call it like this..

    public sub run1()
    do something...
    end sub

    on click function for a button.....

    run1 and that runs it...

    if you wanna choose with one......

    you should create a optional field end use

    if X = 1 then ' or if me.txtbox = 1 then
    elseif x = 2 then 'if me.txtbox = 2 then
    end if

    if you are to run these from any form you sould put them in a module..

    If you REALLY want to use a seperate one.. you can
    run(n) 'should work
    Last edited by theJedi; 01-01-05 at 17:03.

Posting Permissions

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