We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Run a function/sub based on the value of a string

tomnich
tomnich asked
on
Medium Priority
186 Views
Last Modified: 2010-05-03
I want to create a string which is the name of a sub/function in code and run that code, eg

sFunction = "MyFunc"
AMethodofRunning sFunction

where AMethodofRunning is a function which calls the subroutine sFunction.  The question is, what is AMethodofRunning ? (In MS Access you use Application.run sFunction)
Comment
Watch Question

Commented:
You cannot do that with VB6 which is compiled an not interpreted.
Or use select:

Select case sFunction
case "MyFunc1"
  MyFunc1
case "MyFunc2"
  MyFunc2
end select




Commented:
Not. But you can do the following:
select case MyString
case "MyFunc"
      MyFunc arg
case "MyFunc1"
      MyFunc1 arg
case "MyFunc2"
      MyFunc2 arg
end select

Commented:
mirkwood: thanks for you reply...

Commented:
Impossible!!!!
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Commented:
He, chabaud, we probably answered together. Only one minute in between

Commented:
He, funny. Two accounts for one person. Oh Linda.....

Commented:
In VB6, there is a new language feature named CallByName.

You might be able to trick it into doing what you want...


Commented:
Sorry about that...

I must have answered somewhere in the middle there...

Glad you got your answer!

Commented:
to mirkwood: Impossible is not VB !!!!

We have to read the vb6 doc more deeply...
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.