473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Call subroutine by variable value

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
5 5842
"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
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

"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sam | last post by:
I have a function writen in Perl that takes a name-value list (array) as argument and returns a name-value list (array). My question is: How to call this function from PHP and get the returned...
1
by: Rusty | last post by:
Greetings, My problem is I need to call a subroutine but the number of args can be many and vary from call to call. What I'm trying to do is parse a template and capture the data from the...
5
by: Lucy Randles | last post by:
I've written a VBA function that I then need to call in a form. Previously to do this I have written the call procedure in the same module as the function - i.e. Function callfunctionname() Call...
6
by: Jeff Frederick | last post by:
Hello all, I am interested in using the value from a field to call a function. For example I have a table and one of the field names is "Function." So for each record I input the name of the...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
21
by: Cottonwood | last post by:
I want to call a C module from a Fortran program. Whatever I tried - the linker could not find the C module. I know about the leading underscore and switched even that off. I abstracted everything...
1
by: jonniethecodeprince | last post by:
Howdy, I've been trying to do a basic calculation in PERL using a subroutine however i'm confused about a few thing. In the following code what is the signifcants of the list variable "@_" ...
0
by: SenileOwl | last post by:
I'm working in Visual Basic .NET 2005 I'm creating a program that could potentially hold 50 or more subroutines. However, I will only be calling three or four of the subroutines at a time. I...
2
by: jim190 | last post by:
I am relatively new to using VBA and am have been trying for two days to pass a user entered value to my report for filtering when opened. I have the following subroutine in the open event of my...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.