By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 2,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Call subroutine by variable value

P: n/a
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..

Sep 12 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"gabba" <do*****@thespam.comwrote in message
news:45********************@news.tiscali.it...
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()"
Sep 12 '06 #2

P: n/a
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" <do*****@thespam.coma écrit dans le message de news:
45********************@news.tiscali.it...
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..

Sep 12 '06 #3

P: n/a

"McKirahan" <Ne**@McKirahan.comha 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
Sep 12 '06 #4

P: n/a
gabba wrote:
"McKirahan" <Ne**@McKirahan.comha 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.
Sep 12 '06 #5

P: n/a
On Tue, 12 Sep 2006 11:35:49 -0500, gabba <do*****@thespam.comwrote:
is it possible to call a subroutine (or a function) using variable name?
Using Eval poses a significant security risk, so it is preferable to use
GetRef in this situation.

Option Explicit

Sub a()
WScript.Echo "sub a"
End Sub

Dim subname
subname = "a"

Dim s
Set s = GetRef(subname)
s

--
Justin Piper
Bizco Technologies
http://www.bizco.com/
Sep 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.