Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 1999-01-05
10
Medium Priority
?
173 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
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!

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

610 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