Link to home
Start Free TrialLog in
Avatar of tomnich
tomnich

asked on

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)
Avatar of chabaud
chabaud

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




Not. But you can do the following:
select case MyString
case "MyFunc"
      MyFunc arg
case "MyFunc1"
      MyFunc1 arg
case "MyFunc2"
      MyFunc2 arg
end select
mirkwood: thanks for you reply...
Impossible!!!!
ASKER CERTIFIED SOLUTION
Avatar of tomnich
tomnich

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
He, chabaud, we probably answered together. Only one minute in between
He, funny. Two accounts for one person. Oh Linda.....
In VB6, there is a new language feature named CallByName.

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


Sorry about that...

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

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

We have to read the vb6 doc more deeply...