Call subroutine by variable value

G

gabba

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..
 
P

Patrice

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.
 
M

McKirahan

gabba said:
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()"
 
G

gabba

McKirahan said:
"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
 
B

Bob Barrows [MVP]

gabba said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top