?
Solved

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

Posted on 1999-01-05
10
Medium Priority
?
171 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)
0
Comment
Question by:tomnich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 4

Expert Comment

by:chabaud
ID: 1454003
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1454004
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
 
LVL 4

Expert Comment

by:chabaud
ID: 1454005
mirkwood: thanks for you reply...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:Mirkwood
ID: 1454007
Impossible!!!!
0
 
LVL 1

Accepted Solution

by:
tomnich earned 400 total points
ID: 1454008
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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1454009
He, chabaud, we probably answered together. Only one minute in between
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1454010
He, funny. Two accounts for one person. Oh Linda.....
0
 
LVL 4

Expert Comment

by:mcix
ID: 1454012
In VB6, there is a new language feature named CallByName.

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


0
 
LVL 4

Expert Comment

by:mcix
ID: 1454014
Sorry about that...

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

Glad you got your answer!
0
 
LVL 4

Expert Comment

by:chabaud
ID: 1454015
to mirkwood: Impossible is not VB !!!!

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question