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

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)
LVL 1
tomnichAsked:
Who is Participating?
 
tomnichConnect With a Mentor Author Commented:
Here's your answer:

vba.CallByName(MyModule,"MyFunction",VbMethod,Arg1)

MyModule is the module object containg the function, and your function name is "MyFunction", passed in as a string

From you namesake
0
 
chabaudCommented:
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




0
 
MirkwoodCommented:
Not. But you can do the following:
select case MyString
case "MyFunc"
      MyFunc arg
case "MyFunc1"
      MyFunc1 arg
case "MyFunc2"
      MyFunc2 arg
end select
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
chabaudCommented:
mirkwood: thanks for you reply...
0
 
MirkwoodCommented:
Impossible!!!!
0
 
MirkwoodCommented:
He, chabaud, we probably answered together. Only one minute in between
0
 
MirkwoodCommented:
He, funny. Two accounts for one person. Oh Linda.....
0
 
mcixCommented:
In VB6, there is a new language feature named CallByName.

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


0
 
mcixCommented:
Sorry about that...

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

Glad you got your answer!
0
 
chabaudCommented:
to mirkwood: Impossible is not VB !!!!

We have to read the vb6 doc more deeply...
0
All Courses

From novice to tech pro — start learning today.