Call subroutine by variable value

Discussion in 'ASP General' started by gabba, Sep 12, 2006.

  1. gabba

    gabba Guest

    Hi,
    is it possible to call a subroutine (or a function) using variable name?

    Sub a()
    Response.write("sub a")
    End sub

    Sub b()
    Response.write("sub b")
    End sub

    Sub c()
    Response.write("sub c")
    End sub

    Dim subname
    subname = "b"
    **call subname**
    'does exist something like this? or something like the javascript 'eval' ?

    Thanks..
    gabba, Sep 12, 2006
    #1
    1. Advertising

  2. gabba

    Patrice Guest

    See the VBScript "Execute" statement as a last resort...

    You could also use classes (though VBSciprt has limited support for this)
    depending on what is the overall goal.

    --
    Patrice

    "gabba" <> a écrit dans le message de news:
    4506e1de$0$998$...
    > Hi,
    > is it possible to call a subroutine (or a function) using variable name?
    >
    > Sub a()
    > Response.write("sub a")
    > End sub
    >
    > Sub b()
    > Response.write("sub b")
    > End sub
    >
    > Sub c()
    > Response.write("sub c")
    > End sub
    >
    > Dim subname
    > subname = "b"
    > **call subname**
    > 'does exist something like this? or something like the javascript 'eval' ?
    >
    > Thanks..
    >
    >
    >
    Patrice, Sep 12, 2006
    #2
    1. Advertising

  3. gabba

    McKirahan Guest

    "gabba" <> wrote in message
    news:4506e1de$0$998$...
    > Hi,
    > is it possible to call a subroutine (or a function) using variable name?
    >
    > Sub a()
    > Response.write("sub a")
    > End sub
    >
    > Sub b()
    > Response.write("sub b")
    > End sub
    >
    > Sub c()
    > Response.write("sub c")
    > End sub
    >
    > Dim subname
    > subname = "b"
    > **call subname**
    > 'does exist something like this? or something like the javascript 'eval' ?


    "Eval" exists in VBScript and is described as:
    "Evaluates an expression and returns the result."

    "Execute" will do what you want:
    "Executes one or more specified statements."

    Option Explicit
    Const subname = "b"
    Execute subname
    Sub b()
    Response.write("sub b")
    End sub

    Or you could use:
    Const subname = "b()"
    McKirahan, Sep 12, 2006
    #3
  4. gabba

    gabba Guest

    "McKirahan" <> ha scritto nel messaggio

    >> 'does exist something like this? or something like the javascript 'eval'
    >> ?

    >
    > "Eval" exists in VBScript and is described as:
    > "Evaluates an expression and returns the result."
    >
    > "Execute" will do what you want:
    > "Executes one or more specified statements."


    Perfect, really thank you.
    this is what i'm lookink for.

    I mentioned the javascript command eval() cause it's exactly the VbScript
    Execute().

    so...now I know that javascript eval and vbscript eval are false friends ;)

    gabba
    gabba, Sep 12, 2006
    #4
  5. gabba wrote:
    > "McKirahan" <> ha scritto nel messaggio
    >
    >>> 'does exist something like this? or something like the javascript
    >>> 'eval' ?

    >>
    >> "Eval" exists in VBScript and is described as:
    >> "Evaluates an expression and returns the result."
    >>
    >> "Execute" will do what you want:
    >> "Executes one or more specified statements."

    >
    > Perfect, really thank you.
    > this is what i'm lookink for.
    >
    > I mentioned the javascript command eval() cause it's exactly the
    > VbScript Execute().
    >
    > so...now I know that javascript eval and vbscript eval are false
    > friends ;)
    >

    And all three are evil.

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
    Bob Barrows [MVP], Sep 12, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Casey
    Replies:
    3
    Views:
    853
    Casey
    Jan 30, 2004
  2. Alison Bowes
    Replies:
    0
    Views:
    468
    Alison Bowes
    Feb 18, 2005
  3. WC Justice

    Call VBA subroutine from ASP

    WC Justice, Sep 27, 2004, in forum: ASP General
    Replies:
    1
    Views:
    293
    Bob Barrows [MVP]
    Sep 27, 2004
  4. Josef Moellers

    Tk: Call subroutine when MainWindow is realized?

    Josef Moellers, Jan 10, 2005, in forum: Perl Misc
    Replies:
    7
    Views:
    122
    Steve Lidie
    Jan 15, 2005
  5. king
    Replies:
    5
    Views:
    184
Loading...

Share This Page